Actions: composition Complex Action
There are some actions that let you compose actions.
- Sequence action
- Spawn action
- Repeat action
- Repeatforever action
Sequence
Ordered actions allow you to create a series of actions that will be executed in order.
Example:
IDAction1 = [MoveTo Actionwithduration:2 Position:CCP(100,100)];
id Action2 = [ moveBy actionwithduration : 2 position : CCP ( 80 , 80 )];
IDAction3 = [MoveBy Actionwithduration:2Position:CCP(0,80)];
[SpriteRunaction:[Sequence Actions: Action1, Action2, action3,Nil];
TheAction1
Will be executed first. WhenAction1
Finishes, thenAction2
Will be executed. And whenAction2
Finishes, only thenAction3
Will be executed.
* Important: * The inner actions showould have a non infinity time (eg: You can't addRepeatforever
Action inSequence
Action ).
Action1 will be executed first. When action1 is executed, Action2 will be executed. When Action2 ends, it is action3.
Note: This action cannot be an infinite time. For example, you cannot add an action that repeats to the action sequence forever.
Spawn concurrency?
This action allows you to run multiple actions at the same time. The duration of this operation is the longest time of the sub-action.
IDAction = [Spawn Actions:
[ jumpby actionwithduration : 2 position : CCP ( 300 , 0 ) height : 50 jumps : 4 ],
[Rotateby Actionwithduration:2 Angle:720],Nil];
[SpriteRunaction: Action];
Repeat already exists.
This repeated action allows you to repeat an action for a limited number of times. Example:
IDA1 = [MoveBy Actionwithduration:1 Position:CCP(150,0)];
IDAction1 = [Repeat Actionwithaction:
[Sequence Actions:[Place Actionwithposition:CCP(60,60)], A1,Nil]Times:3];
[SpriteRunaction: Action1];
Repeatforever always repeats
Repeating this action forever is a special action that will continue. Because its time cannot be measured.
Example:
IDA1 = [MoveBy Actionwithduration:1 Position:CCP(150,0)];
IDAction2 = [Repeatforever Actionwithaction:
[Sequence Actions: [[A1Copy]Autorelease], [A1Reverse],Nil];
[SpriteRunaction: Action2];
Note: This action that is always repeated is not a valid intervalaction and cannot be placed in a sequence action.