Skip to content

Make a sprite grow and shrink

Combine repeat and changeSize inside a forever loop to create a smooth pulsing animation.

whenGreenFlag(() => {
forever(() => {
repeat(10, () => {
changeSize(5);
wait(0.05);
});
repeat(10, () => {
changeSize(-5);
wait(0.05);
});
});
});

The sprite grows by 5% ten times, then shrinks by 5% ten times — back to its original size — and repeats forever. Adjust the numbers to change how big it gets and how fast it pulses.

  • whenGreenFlag — run code when the green flag is clicked
  • forever — repeat a block of code indefinitely
  • repeat — run a block of code a fixed number of times
  • changeSize — change this sprite’s size by an amount
  • wait — pause the script for a number of seconds
All recipes