(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 seperately. Stamping will also by default stamp a bitmap image of the sprite. 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.
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 are:
- Tower Defense games
- Many arcade-style games
- Particles such as fireworks and snow
- RNG-based projects[clarify]
- Mouse trails
- Any project needing many repetitive sprites
There are three blocks related to cloning, all of which are found in the control palette:
create clone of [myself v]— clones the sprite selected
when I start as a clone— when a sprite is cloned, this hat block runs in the newly made clone
delete 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.
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.
Cloning in Scratch Mods
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 uses this style of cloning.
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.)