Skip to content

Move a sprite with the arrow keys

Make a sprite respond to the arrow keys by nudging its position whenever a key is pressed.

whenKeyPressed("right arrow", () => {
changeX(10);
});
whenKeyPressed("left arrow", () => {
changeX(-10);
});
whenKeyPressed("up arrow", () => {
changeY(10);
});
whenKeyPressed("down arrow", () => {
changeY(-10);
});

Each press moves the sprite 10 steps in that direction.