how can I use animation in cocos2d?

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’)

Leave a Comment