New! Explore our Programming Academy and AI Tutor - learn to code from scratch, free to start. Explore Now
Programming› Scratch› Clones, Timers and Levels

Clones, Timers and Levels

💻 Scratch

Use clones and timers to create enemies, effects and level pressure.

Lesson 8 of 9 Tutorial
0 of 9 completed

Clones are copies of a sprite that run their own scripts. They are perfect for falling objects, bullets and explosions.

By the end of this lesson you can:
  • Create and delete clones.
  • Give each clone its own behaviour.
  • Use the timer to add pressure.

Create a Clone

The create clone of myself block makes a copy. A when I start as a clone hat block runs only for that copy.

when green flag clicked
forever
  wait (1) seconds
  create clone of [myself v]
end

when I start as a clone
go to x: (pick random -200 to 200) y: (180)
repeat until <(y position) < (-170)>
  change y by (-4)
end
delete this clone

Delete Clones

Every clone should end with delete this clone. Scratch has a limit on clones, so leaked clones eventually stop the project from creating more.

Timers and Levels

Use the timer to measure elapsed time, or a countdown variable to create urgency. Increase the falling speed when the level rises.

Warning A clone runs its own copy of the script. Variables that should be shared must be global, not local to the sprite.

Practice

  1. Create one clone every two seconds.
  2. Make each clone disappear when clicked.
  3. Increase falling speed after every ten points.

Hands-on exercise

Create a falling-object effect.
1. Every second, create a clone of the object.
2. Send each clone to a random x position at the top.
3. Move it down until it leaves the stage.
4. Delete the clone at the bottom.

Recap

Clones let one sprite act like many. Create them carefully, give each a job and always delete them when finished.

Example

when green flag clicked
forever
  wait (1) seconds
  create clone of [myself v]
end

when I start as a clone
go to x: (pick random -200 to 200) y: (180)
repeat until <(y position) < (-170)>
  change y by (-4)
end
delete this clone

Exercises

Exercise 1. Falling objects Medium
Create a falling-object effect.
1. Every second, create a clone of the object.
2. Send each clone to a random x position at the top.
3. Move it down until it leaves the stage.
4. Delete the clone at the bottom.
Scratch exercise-1.txt
Expected Output
A new object falls from a random position every second and disappears at the bottom.

Lesson Nav

Lesson sections