how can I use animation in cocos2d?

Md Nasir Uddin picture Md Nasir Uddin · Jan 28, 2009 · Viewed 25.7k times · Source

I am trying to develop a Roulette game for iPhone. How can I animation (spin) the Roulette board?

Answer

Stanislav picture Stanislav · Jul 26, 2009

It's quite simple in Cocos2D:

[sprite runAction:[RotateBy actionWithDuration:dur angle:360]];

to make one turn or

id action = [RepeatForever actionWithAction: [RotateBy actionWithDuration:dur angle:360]];
[sprite runAction:action];

and

[sprite stopAction:action];

if you need to rotate continuously.

Don't forget to make sure that sprite transformAnchor is set to center of the image. And I guess next question should arise - how to make it stop smoothly ;)

More on actions: http://lethain.com/entry/2008/oct/03/notes-on-cocos2d-iphone-development (it's for older version, so it uses deprecated 'do' instead of 'runAction')