(Redirected from Clones)
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, scripts, and variables as the original but is otherwise independent.
Cloning is different from stamping in that stamping only produces an image of the sprite on the stage, whereas clones are individual sprites that are able to interpret scripts and run separately. Stamping can also only stamp a bitmap image of the sprite, whereas a clone can be a vector image. It is also different from the "duplicate" option in the sprite menu 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 could be made in Scratch 2.0.[2]
Usage
Cloning is commonly used when a project has many similar sprites doing similar things. Because clones are created by the project rather than the user, cloning prevents the user from needing to make the same changes to each of many sprites. Some common uses of cloning include:
- Tower Defense games
- Many arcade-style games
- Particles such as fireworks and snow
- RPG-based projects[clarify]
- Mouse trails
- Any project needing many repetitive sprites
Blocks
There are three blocks related to cloning, all of which are found in the control palette:
create clone of (myself v)
— clones the sprite selectedwhen I start as a clone
— when a sprite is cloned, this hat block runs in the newly made clonedelete this clone
— deletes the clone it runs in and stops all of its scripts
Clones can also create clones, which is often used for recursion.
Variable Usage
If a variable is marked as "for this sprite only", each clone of the sprite will have its own value for the variable that is separate from the original sprite and all other clones. This can be used to store information for individual clones, such as health for enemies in some Game Projects.
See Also
- Advanced Clone Usage
- Detecting Clones
- Using Clones for Particle Effects
- Suggestion of Clones (Archived)