Skip to content

Follow the mouse

Read the mouse coordinates every frame and move the sprite to that position.

whenGreenFlag(() => {
forever(() => {
goto(getMouseX(), getMouseY());
});
});

The sprite snaps to the cursor instantly on every tick. To make it lag behind the cursor for a smoother feel, use glide with a very short duration instead.

whenGreenFlag(() => {
forever(() => {
glide(0.05, getMouseX(), getMouseY());
});
});
  • whenGreenFlag β€” run code when the green flag is clicked
  • forever β€” repeat a block of code indefinitely
  • goto β€” move to a position instantly
  • glide β€” animate to a position over time
  • getMouseX β€” get the mouse x position
  • getMouseY β€” get the mouse y position
All recipes