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.
Functions used
Section titled “Functions used”whenKeyPressed— run code when a key is pressedchangeX— move along the x axischangeY— move along the y axis