Scratch Tutorial: Who is really Wukong

In Journey to the West, there is a set of "true and false Monkey King", Wukong six ears monkeys became really looks like Goku and real to the enemy, playing their hands full.

In Scartch, we often use a body to generate more clones , which has important implications in the development process. However, in practice, each clone looks the same, how to distinguish in the proceedings clone body then?

Here we need to distinguish between two questions:

 

The first of how to distinguish between a body and the cloning thereof. The second is how to identify and distinguish a plurality of different clones.

Today, we put the question to distinguish between knowledge and clones of analysis.

What is the relationship with the body of clones is it? 

      When the body generated clones, and clones having a body experience the same position, orientation , size, effects, shapes, sounds, local variables, and programs. Since they have the same program, so the response message, the body, and clones may also accept message, produce erroneous results. The body and therefore must distinguish clones.

Below, we analyze the method of distinguishing from the life cycle of the clones, clone life cycle include the following several processes.

Who is really Wukong                      

1

Create a clone: ​​is the use of "clone" building blocks generated can generate a character clone, clone or generate additional roles.

2

When clone generation, will stimulate "When started as a clone," the event , you can do some initialization clones here.

3

Delete clones, clones can delete your last. Only after deleting all the resources clone was released.

 

The body of the life cycle of it?

The body has always been there, just joined this body role in the project, this role will exist until this role will be deleted from the project to release all resources.

       One very important difference is that only the body can receive a green flag event . Because when you click the green flag, the system will first remove all clones, only this time on the stage body, it was only acceptable body green flag event.

Can be known from the above analysis, the occurrence of the event body and the clones are different.

Only the green body may receive an event flag, may receive only clone "when used as clones start" event.

So that we can distinguish between the two.

 

Who is really Wukong

Typically follows, a local variable may be set "is a clone" is set to 0 when the green flag indicates not clones, in the "when clones started as" is, then the variable is set to 1, indicating a clones.

Procedures are as follows:

Who is really Wukong

So the value of this variable to indicate whether a clone.

Here is the problem of distinguishing clone, in the generation of multiple clones, how to distinguish between the different clones of it?

May be used in such a manner, the establishment of a local variable ID, enable different values ​​for each clone, it can be used to distinguish a plurality of clones. So how do you set this value it? After cloning can change the value in the body, since the body clones inherited variable value, so each can have different values.

Procedures are as follows:

Who is really Wukong

Can be seen, the process of generating the 10 clones, each clone has a a different ID. After clicking the green flag and press the space bar, you get the following results.

 

Who is really Wukong

Each clone obtained can be seen that a different ID from 1 to 10, that is to say the body 11.

 

in conclusion

      1 clone is Scratch an important function, it is important to distinguish between clones in the art in the program.

2 distinguish two aspects, it is to distinguish between a body and a clone, and the other is to distinguish between different clones.

3 distinguish between the body and the clone approach is beneficial both for different events.

4 distinguish between different clones is to use a variable identifier.

Guess you like

Origin www.cnblogs.com/scratch3/p/10935766.html