Monthly Archive for December, 2008

Page 2 of 2

cocos2d: Repeat vs. RepeatForever vs. IntervalActions

cocos2d v0.6.0 introduces a new action: RepeatForever. As you can imagine, this action will repeat forever the inner action.

Example:

id jump = [JumpBy actionWithDuration:3 position:cpv(400,0)           height:50 jumps:4];[node do: [RepeatForever actionWithAction:           [Sequence actions: jump, [jump reverse], nil]       ]];

The old action Repeat is still present in v0.6. In fact, it includes some fixes. Now it is possible to Repeat a Sequence of Repeat of Sequences of Repeat… but you can’t use it to repeat an action forever.

Repeat as well as Sequence are IntervalAction actions. This means that they occur during a certain period of time: they start and they stop. You can accelerate, or change the speed of any any IntervalAction using the Accelerate, AccelDeccel and Speed actions, but if an action is executed forever, then it is not an IntervalAction.

This means that:

  • You can Repeat a Sequence of Repeat of Accelerate of Sequence of Repeat of Speed of Sequence…
  • You can’t Sequence a RepeatForever action since Sequence only works with IntervalActions. Again: RepeatForever is not an IntervalAction since it hasn’t an stopping time.
  • But you can RepeatForever a Sequence of Repeat of Sequence of… Note that the RepeatForever is executed first.

Working Example: SpriteDemo example. See SpritesDemo.m file.