Skip to content

Bounce off the edge

Move the sprite forward every tick and flip its direction automatically when it reaches a stage edge.

whenGreenFlag(() => {
forever(() => {
move(5);
ifOnEdgeBounce();
});
});

The sprite travels in its current direction and reverses when it hits a wall. Change 5 to a larger number for faster movement.

  • whenGreenFlag — run code when the green flag is clicked
  • forever — repeat a block of code indefinitely
  • move — move forward by a number of steps
  • ifOnEdgeBounce — bounce off the edge of the stage if touching it
  • setRotationStyle — set how this sprite rotates when its direction changes
All recipes