Dieses Dokuwiki verwendet ein von Anymorphic Webdesign erstelltes Thema.

Actions: Composition

There are some actions that let you compose actions.

  • Sequence action
  • Spawn action
  • Repeat action
  • RepeatForever action


The CCSequence action is a list of actions. The actions are executed in the order that they are defined.


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-infinite time (e.g.: You can't add a CCRepeatForever action in a CCSequence action).


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],
[sprite runAction:action];


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]
[sprite runAction:action1];


The CCRepeatForever action is a special action. Since it will repeat an action forever, its duration can't be measured.


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.

prog_guide/actions_composition.txt · Last modified: 2010/09/20 08:00 by ryandesign
Trace: actions_composition
Dieses Dokuwiki verwendet ein von Anymorphic Webdesign erstelltes Thema.
CC Attribution-Noncommercial-Share Alike 3.0 Unported
www.chimeric.de Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0