i currently try to create a scrolling, where i can scroll the screen up and down with my finger. I found the g.scroll(x,y) method, this however deletes every pixel that leaves the screen.
I tried to use the drag event to move the position of my objects to draw every time a drag event is being emitted. This however causes jumps between each render, if there are more objects that need a redraw.
Is there a way to have a smooth scrolling with many objects?
An code example with both scrolling methods. You can change the scroll method with the press of the hardware button.
let smoothScrolling= true;
let y = 30;
let numberOfObjects = 50;
function render() {
g.clear();
g.setFontVector(20);
if (smoothScrolling) {
g.drawString('Smoot', 50,30);
} else {
g.drawString('Own implementation', 50,y);
}
for (let i = 0; i< numberOfObjects; i++) {
g.fillRect(10, y, 20, y + 10);
}
}
const onDrag = (e) => {
if (smoothScrolling) {
g.scroll(0, e.dy);
} else {
y += e.dy;
render();
}
};
Bangle.on('drag', onDrag);
setWatch(() => {
smoothScrolling = !smoothScrolling;
y = 30;
render();
}, BTN1, {repeat: true, edge: "falling"});
render();
Espruino is a JavaScript interpreter for low-power Microcontrollers. This site is both a support community for Espruino and a place to share what you are working on.
Hi evereyone,
i currently try to create a scrolling, where i can scroll the screen up and down with my finger. I found the g.scroll(x,y) method, this however deletes every pixel that leaves the screen.
I tried to use the drag event to move the position of my objects to draw every time a drag event is being emitted. This however causes jumps between each render, if there are more objects that need a redraw.
Is there a way to have a smooth scrolling with many objects?
An code example with both scrolling methods. You can change the scroll method with the press of the hardware button.