Feel free to fix/add documentation to the wiki
Actions: Composition
There are some actions that let you compose actions.
- Sequence action
- Spawn action
- Repeat action
- RepeatForever action
Sequence
The CCSequence action is a list of actions. The actions are executed in the order that they are defined.
Example:
id action1 = [CCMoveTo actionWithDuration:2 position:ccp(100,100)]; id action2 = [CCMoveBy actionWithDuration:2 position: ccp(80,80)]; id action3 = [CCMoveBy actionWithDuration:2 position: ccp(0,80)]; [sprite runAction: [CCSequence actions:action1, action2, action3, nil]];
The action1 will be executed first. When action1 finishes, then action2 will be executed. And when action2 finishes, only then action3 will be executed.
*IMPORTANT:* The inner actions should have a non infinity time (eg: You can't add a CCRepeatForever action in a CCSequence action).
Spawn
The CCSpawn action lets you run several actions at the same time. The duration of the CCSpawn action will be the duration of the longest sub-action.
id action = [CCSpawn actions: [CCJumpBy actionWithDuration:2 position:ccp(300,0) height:50 jumps:4], [CCRotateBy actionWithDuration: 2 angle: 720], nil]; [sprite runAction:action];
Repeat
The CCRepeat action lets you repeat an action a limited number of times.
Example:
id a1 = [CCMoveBy actionWithDuration:1 position:ccp(150,0)]; id action1 = [CCRepeat actionWithAction: [CCSequence actions: [CCPlace actionWithPosition:ccp(60,60)], a1, nil] times:3]; [sprite runAction:action1];
RepeatForever
The CCRepeatForever action is an special action. Since it will repeat an action forever, it's duration can't be measured.
Example:
id a1 = [CCMoveBy actionWithDuration:1 position:ccp(150,0)]; id action2 = [CCRepeatForever actionWithAction: [CCSequence actions: [[a1 copy] autorelease], [a1 reverse], nil] ]; [sprite runAction:action2];
*IMPORTANT*: CCRepeatForever is not a valid CCIntervalAction. You can't use a CCRepeatForever inside a CCSequence action.
Trace: » templates » prog_guide » 0_99_0 » license » actions_ease » start » hello_world » actions » actions_special » actions_composition