Game Development Reference
In-Depth Information
With the CCFollow action, you can instruct a node to follow another node. For ex-
ample, to have a label follow the player character sprite, the code might look
something like this:
[label runAction:[CCFollow actionWithTarget:playerSprite]];
You can also have actions or even a whole sequence of actions repeat (loop) forever
with CCRepeatForever . You can create endlessly looping animations this way, for
example. This code lets a node rotate forever like an endlessly spinning wheel:
CCRotateBy* rotateBy = [CCRotateBy actionWithDuration:2 angle:360];
CCRepeatForever* repeat = [CCRepeatForever actionWithAction:rotateBy];
[myNode runAction:repeat];
You can use the CCSpeed action to influence the speed of an action while it's running.
Let's take the earlier rotation example and wrap it with a CCSpeed action:
CCRotateBy* rotateBy = [CCRotateBy actionWithDuration:2 angle:360];
CCRepeatForever* repeat = [CCRepeatForever actionWithAction:rotateBy];
CCSpeed* speedAction = [CCSpeed actionWithAction:repeat speed:0.5f];
speedAction.tag = 1;
[myNode runAction:speedAction];
Now the node will take twice as long to make a full revelution because the CCSpeed
action's speed is set to 0.5f . You can change the speed property of the CCSpeed
action later to influence the speed of the wrapped action while it's running. Without
CCSpeed , you'd have to create new CCRotateBy and CCRepeatForever actions
to accomplish a change in speed. That would not only waste precious CPU time, it
might also cause stutters or jumps in the rotation animation.
To make the node suddenly rotate faster, you only need to get the speed action and
modify its speed property:
CCSpeed* speedAction = (CCSpeed*)[myNode getActionByTag:1];
speedAction.speed = 2;
Search Nedrilad ::




Custom Search