简体   繁体   中英

How to move a sprite around the circumference of a circle only once with CCAction in Cocos2d-iPhone

I'm new to Cocos2d. And I know the similar question has been asked.

But I don't know how to move a sprite in ONLY ONE circle, and after that, it triggers the completion block or invoke a callback.

// Don't know how to create an action which moves the sprite in a circle 
CCAction *moveSpriteInACircle;

// the completion callback block
CCCallBlockN * actionMoveDone = [CCCallBlockN actionWithBlock:actionMoveDoneBlock];

// run the action sequence
[sprite runAction:[CCSequence moveSpriteInACircle, actionMoveDone, nil]];

Easiest way is to put the sprite as a child to a CCNode and offset it so it is on the desired circle's circumference. Then run a CCRotateBy action (360 degrees) on the sprite's parent node. If you don't want the sprite to rotate while moving around the rotation, run another CCRotateBy on the sprite but in the opposite direction (-360 degrees).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM