Skip to content

Create a clone army

Use createClone to spawn copies of a sprite, then give each clone its own behavior with whenCloneStart.

// The original sprite creates 5 clones then hides itself
whenGreenFlag(() => {
hide();
repeat(5, () => {
createClone();
});
});
// Each clone bounces around independently
whenCloneStart(() => {
show();
changeX(Math.random() * 300 - 150);
changeY(Math.random() * 200 - 100);
forever(() => {
move(4);
ifOnEdgeBounce();
});
});

Each clone starts at a random position and bounces around the stage on its own. The original sprite hides so only the clones are visible.

  • whenGreenFlag β€” run code when the green flag is clicked
  • hide β€” hide this sprite
  • repeat β€” run a block of code a fixed number of times
  • createClone β€” create a clone of this sprite
  • whenCloneStart β€” run code when a clone of this sprite starts
  • show β€” make this sprite visible
  • changeX β€” move along the x axis
  • changeY β€” move along the y axis
  • 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
  • deleteThisClone β€” delete this clone
All recipes