(Redirected from Clone)

A diagram showing how cloning works. The clones of a parent sprite can be different, as the facial expressions show.

Cloning is a feature that allows a sprite to create a copy of itself while the project is running. Each clone has the same costumes, sounds, and scripts as the original but is otherwise independent.

Cloning is different from stamping in that stamping only produces a picture of the sprite on the stage, whereas clones are individual sprites that can run scripts and move around. It is different from duplication in that ordinary duplicates are permanent and appear in the sprite pane, whereas clones do not appear in the sprite pane, disappear when the stop sign is pressed, and can be sensed by other sprites using the Touching ()? block with the original sprite as its input.

There may only be 300 clones at once to prevent excessive lagging or crashes,[1] but 301 can be made in Scratch 2.0, as shown by this project by the Scratch Team member thisandagain.

Uses of Cloning

Cloning should be used whenever a project should have many similar sprites doing similar things. Because clones are made by the project rather than the user, cloning prevents the user from needing to make the same changes to each of many sprites. For example, cloning can be used for:

  • Tower Defence games
  • Many arcade-style games
  • Special effects such as fireworks and snow
  • RNG based projects[clarify]
  • Mouse trails
  • Any project needing many repetitive sprites

Blocks

Note Note: Click on a block to learn more about it.

There are three blocks related to cloning, all of which are found in the Control palette:

A clone may use Create Clone of () to recursively clone itself.

Variable Usage

If a variable is marked "for this sprite only", each clone of the sprite it belongs to will have its own variable with the given name, just as each clone has its own position, direction, pen, etc. This can be used to make clones behave differently from each other.

Cloning in Scratch Mods

There are two different types of cloning implemented in different Scratch modifications. They are commonly referred to as "Panther-style cloning" and "BYOB-style cloning".

Panther

In Panther-style cloning, a clone is a copy of a sprite, but it does not appear in the sprite pane, changes made to the original do not affect the clone, and it is deleted when the stop sign is pressed. Much of the code for cloning used in Panther was already present in Scratch 1.4. Scratch 2.0 and onward use this style of cloning.

BYOB

In BYOB-style cloning, each clone appears in the sprite pane, and may have scripts all of its own. Clones are created with the block (clone :: operators), which clones a sprite and reports the new clone; sprites are first class in BYOB. (The other important differences between cloning in Scratch and cloning in BYOB are that a clone in BYOB is not merely a copy of the original sprite but can share attributes, and that one can use the () of () to ask a sprite (whether it is a clone or not) for the value of a particular attribute. Snap!, the successor of BYOB 3, offers both temporary and permanent clones.)

See Also

References

  1. post:13617