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 itselfwhenGreenFlag(() => { hide(); repeat(5, () => { createClone(); });});
// Each clone bounces around independentlywhenCloneStart(() => { 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.
Functions used
Section titled βFunctions usedβwhenGreenFlagβ run code when the green flag is clickedhideβ hide this spriterepeatβ run a block of code a fixed number of timescreateCloneβ create a clone of this spritewhenCloneStartβ run code when a clone of this sprite startsshowβ make this sprite visiblechangeXβ move along the x axischangeYβ move along the y axisforeverβ repeat a block of code indefinitelymoveβ move forward by a number of stepsifOnEdgeBounceβ bounce off the edge of the stage if touching itdeleteThisCloneβ delete this clone