Game Development Reference
In-Depth Information
Only the otherNode will run the action because it was the last node to use it. Actions
only act on a single node, and therefore myNode won't move at all. If you want both
nodes to move, you have to create two instances of the CCMoveTo class. There's
really no other way around this.
Action Sequences
When you add several actions to the same node, they all perform their duties at the
same time. For example, you could have an object rotate and fade out at the same time
by adding the corresponding actions. But what if you want to run the actions one after
the other?
Sometimes it's more useful to sequence actions, meaning as soon as one action has
completed its job, the next one starts running. That's where CCSequence comes in.
It's so powerful and frequently used, it deserves an extra mention. You can use any
number and type of actions in a sequence, which makes it easy to have a node move to
a target location and, at arrival, have it rotate around and then fade out, each action fol-
lowed by the next one until the sequence is complete.
Here's how to cycle a label's colors from red to blue to green while waiting 1 second
each after the red and blue tinting actions have run:
CCTintTo* tint1 = [CCTintTo actionWithDuration:4 red:255 green:0 blue:0];
CCDelayTime* wait1 = [CCDelayTime actionWithDuration:1];
CCTintTo* tint2 = [CCTintTo actionWithDuration:4 red:0 green:0 blue:255];
CCDelayTime* wait2 = [CCDelayTime actionWithDuration:1];
CCTintTo* tint3 = [CCTintTo actionWithDuration:4 red:0 green:255 blue:0];
CCSequence* sequence = [CCSequence actions:tint1, wait1, tint2, wait2, tint3, nil];
[label runAction:sequence];
You can also use a CCRepeatForever action with the sequence:
CCSequence* sequence = [CCSequence actions:tint1, tint2, tint3, nil];
CCRepeatForever* repeat = [CCRepeatForever actionWithAction:sequence];
[label runAction:repeat];
And being able to modify the speed of the entire repeating sequence can come in handy
too:
Search Nedrilad ::




Custom Search