Create Clone of () | |
create clone of (myself v) | |
Category | Control |
Type | Stack |
Introduced in | 2.0 |
The Create Clone of () block is a control block and a stack block. It creates a clone of the sprite in the argument. It can also clone the sprite it is running in, creating clones of clones, recursively.
History
create clone:: control
In the Scratch Day 2011 pre-alpha, this block was called Create Clone, with no argument. As such, it could only create a clone of the sprite it ran in; not others. The advantage of an argument is that a single sprite, or the stage, can clone several different sprites upon an event. In other programming languages including Java, C++, C#, etc., there are objects and/or classes, similar to clones.
Example Uses
Cloning is often used when a sprite must make copies of itself. Below are some examples:
- Unlimited bullets in a shooting game
when [space v] key pressed create clone of (bullet v)
when I start as a clone go to (player v) point towards (mouse-pointer v) repeat until < <touching (edge v)?> or <touching (target v)?> > move (3) steps end delete this clone
- Creating several copies of a sprite to click
when gf clicked set [sprites to find v] to [10] repeat (sprites to find) create clone of (Sprite1 v) end
when I start as a clone wait until <<mouse down?> and <touching (mouse-pointer v)?>> say [You got me!] for (2) seconds hide change [sprites to find v] by (-1)