πŸ‘―
CodingπŸ”¬ Ages 11-13Intermediate 11 min read

Cloning Sprites in Scratch

A step-by-step middle-school lesson on clones in Scratch: how 'create clone', 'when I start as a clone', and 'delete this clone' work, why clones beat copying sprites, and a worked falling-objects project. With a quiz.

Key takeaways

  • A clone is a temporary copy of a sprite that runs its own scripts
  • 'create clone of myself' makes a new clone; 'when I start as a clone' is the code each clone runs
  • 'delete this clone' removes a clone to keep the project fast
  • Clones let one sprite produce many objects, like raindrops or enemies, without copying it

What is a clone?

Imagine you are making a game where rain falls from the sky. You need lots of raindrops β€” maybe twenty on screen at once. You could draw twenty raindrop sprites by hand, but that would be slow, and changing how they fall would mean editing all twenty. There is a much smarter way: clones.

A clone is a temporary copy of a sprite. It looks the same, sits at a position on the stage, and runs scripts β€” but it is created while the program is running and disappears when you are done with it. One raindrop sprite can spawn a whole storm of clones, each falling on its own. Write the falling behaviour once, and every clone follows it.

Clones are one of the most powerful tools in Scratch, used for bullets, enemies, snowflakes, stars and particle effects. If Scratch is new to you, work through getting started with Scratch first. Clones often work together with messages, so broadcasting messages in Scratch is a useful companion.

The three clone blocks

All clone control comes from the Control category, with three main blocks:

  • create clone of [myself] β€” makes a new clone. You can clone yourself or another sprite, but cloning myself is the usual choice.
  • when I start as a clone β€” a hat block. The script under it runs once for each clone, the moment that clone is born. This is where you put a clone's behaviour.
  • delete this clone β€” removes the clone that runs it. Use it to tidy up clones once their job is finished.

There is one more idea to know: when a clone is created, it begins as an exact copy of the original sprite at that instant β€” same position, costume, size and direction. So you usually set the original up the way you want, then clone it.

Step 1: Create a single clone

Let's start tiny. Put this on a sprite β€” the cat is fine:

when green flag clicked
create clone of [myself]
when I start as a clone
go to x: (pick random -200 to 200) y: 150

Click the green flag. A second cat appears at a random spot near the top. That second cat is the clone. The original cat ran create clone of myself, and the clone ran when I start as a clone, which moved it.

Notice the two scripts have different starting hats. The original is driven by the green flag; the clone is driven by when I start as a clone. They are separate lives for the same sprite.

Step 2: Create many clones with a loop

One clone is not very exciting. Let's make a downpour by cloning inside a loop. If loops need a refresher, see loops and repeats.

when green flag clicked
hide
forever
  wait 0.3 seconds
  create clone of [myself]
when I start as a clone
go to x: (pick random -220 to 220) y: 170
show
repeat 40
  change y by -5
delete this clone

Click the green flag and watch a steady stream of clones rain down. Let's read both scripts carefully:

  1. The original hides itself (so you do not see the spawner), then loops forever, creating one clone every 0.3 seconds.
  2. Each clone runs the second script independently. It jumps to a random spot at the top, shows itself, then repeat 40 moves it down 5 steps at a time. When it reaches the bottom, delete this clone removes it.

This is the heart of clones: the spawner makes them, and each clone lives out its own little script. The delete this clone at the end is essential β€” without it, clones would pile up until you hit the 300-clone limit and the rain would stop.

Step 3: Why clones beat copying sprites

You might wonder why not just duplicate the sprite forty times. Clones win for three reasons:

  1. Write the behaviour once. The falling code lives in a single when I start as a clone script. Change change y by -5 to -8 and every clone falls faster β€” no need to edit forty sprites.
  2. You control how many exist. Clones are created and deleted while the game runs, so you can have ten on screen now and thirty a moment later. Hand-made copies are fixed.
  3. It stays organised. Forty duplicate sprites clutter the sprite list. One sprite that spawns clones is clean and easy to manage.

Step 4: Giving each clone its own settings

Clones become really powerful when each one behaves a little differently β€” some raindrops falling faster than others, for example. The trick is a variable set to "for this sprite only", which gives each clone its own private copy.

  1. Make a variable called speed and choose For this sprite only when you create it.
  2. Set it before cloning, or right as the clone starts:
when I start as a clone
set [speed] to (pick random 3 to 9)
go to x: (pick random -220 to 220) y: 170
show
repeat 40
  change y by (-1 * (speed))
delete this clone

Because speed is per-sprite, each clone rolls its own random speed, so the rain falls at varied speeds and looks natural. A variable set to "for all sprites" would be shared, and all clones would move identically. The difference between these two kinds of variable matters a lot with clones.

A worked project: catch the falling stars

Let's build a small complete game using everything above. Stars fall from the sky and the player catches them with a basket at the bottom.

The basket (a sprite you steer):

when green flag clicked
go to x: 0 y: -150
forever
  set x to (mouse x)

The star (the spawner and clone behaviour):

when green flag clicked
hide
set [score] to 0
forever
  wait 1 seconds
  create clone of [myself]
when I start as a clone
go to x: (pick random -220 to 220) y: 170
show
forever
  change y by -6
  if <touching [Basket]?> then
    change [score] by 1
    delete this clone
  if (y position) < -170 then
    delete this clone

Trace one star, step by step:

  1. The original star hides and resets score, then spawns a clone every second.
  2. Each clone appears at the top and falls with change y by -6 inside its own forever loop.
  3. If the clone is touching [Basket]?, it adds a point and deletes itself β€” caught!
  4. If it falls past the bottom (y position < -170), it deletes itself β€” missed.

To keep score on screen, tick the score variable's checkbox. For more on score variables, see variables and score in Scratch.

Common mistakes and how to fix them

  • Clones never disappear and new ones stop spawning. You forgot delete this clone. Add it where each clone finishes its job.
  • You can see the spawner sprite. Add hide to the original under the green flag; clones can still show themselves.
  • All clones behave identically when you wanted variety. Use a variable set to for this sprite only so each clone gets its own value.

Reading your scripts in order to find these problems is called debugging, and every coder does it.

Try it: make it your own

You can now spawn and control clones. Try these challenges:

  • Add a miss counter: make a lives variable, lose a life when a star falls past the basket, and end the game at zero.
  • Mix in bad objects: clone a "bomb" too; if the basket catches it, lose points.
  • Speed up over time: lower the wait between clones as the score climbs, so the game gets harder.
  • Fireworks: on a click, create a burst of clones that fly outward in different directions, then delete after a moment.

Clones turn one sprite into a crowd. Once you are comfortable spawning and deleting them, you can build rain, enemies, bullets and particle effects in any project. Have fun cloning! πŸ‘―

Quick quiz

Test yourself and earn XP

What is a clone in Scratch?

Which block runs the code for each clone the moment it is born?

Why should you usually add 'delete this clone' at the end of a clone's script?

What is the advantage of clones over making many copies of a sprite by hand?

In a falling-rain project, where does the 'change y by -5' that makes a drop fall belong?

FAQ

Yes. Scratch allows up to 300 clones at once across the whole project. If you keep creating clones without deleting them, you will hit that limit and no new clones will appear. Adding 'delete this clone' when each clone finishes its job keeps you well under the limit.

It depends on the variable. A variable set to 'for this sprite only' gives each clone its own private copy, which is great for things like a clone's own speed. A variable set to 'for all sprites' is shared, so every clone reads and writes the same value.