From Test-Scratch-Wiki

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

Cloning is a feature that allows a 角色 to create a clone, or semi-duplicate, of itself, while the 專案 is running. This can be useful in tower defense games, for example, for a wave of objects. Clones of a sprite will be the same as the original, or parent sprite, but as a separate instance. Clones inherit the parent's scripts, costumes, sounds, and properties, but can then be modified. There is a limit of 300 clones per project to prevent excessive lagging or crashes,[1] but 301 can be made.

Cloning 積木相關

In Scratch 2.0, there are three blocks related to cloning. All can be found in the Control palette.

Create Clone of ()

Main article: Create Clone of ()
分身 [自己 v] 建立

This block will clone the sprite it runs in. Its version in the Scratch Day 2011 prealpha had no dropdown insert to select a sprite.

create clone // category=control

It is also possible to clone other clones recursively.

When I Start as a Clone

Main article: When I Start as a Clone

This 半圓形積木 activates when a clone is created. It only runs in the newly created clone, not previous clones or the parent.

Delete This Clone

Main article: Delete This Clone

This 平底形積木 will delete the clone it runs in.

Duplicating Sprites

Not to be confused with cloning, sprites can be duplicated by two methods:

  1. Right click on a sprite in the sprites area or stage, and select "duplicate".
  2. Select the duplicate tool (looks like a stamp) above the stage area and to the left of the presentation buttons. Then click on the sprite you want to be duplicated.

This will make the new sprite appear in the new sprites area with all of the same costumes, scripts, and sounds.

Variable Usage

變量s for all sprites will be the same for each clone, but variables for this sprite only will be different for each clone.

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".

In Panther-style cloning, a clone inherits its parent's properties, but is only a clone of it, not a new sprite. Other sprites can sense the clones, using the 碰到 ()?積木, with the parent as its 參數. The code for Panther-style cloning was actually implemented in Scratch 1.4, hinting that it was a planned feature, but wasn't added. Scratch 2.0 uses this style of cloning.

In BYOB-style cloning, a clone is a new sprite in the sprite list, with editable data all of its own. Clones are created with an Operators 積木 "(clone)", which clones a sprite and reports a reference to it, which can then be used to control it.



Cookies help us deliver our services. By using our services, you agree to our use of cookies.