简体   繁体   English

如何在Cocos2d-iPhone中使用CCAction在圆周上仅移动一次精灵

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

I'm new to Cocos2d. 我是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. 最简单的方法是将子对象作为子对象放置到CCNode并使其偏移,使其位于所需圆的圆周上。 Then run a CCRotateBy action (360 degrees) on the sprite's parent node. 然后在精灵的父节点上运行CCRotateBy操作(360度)。 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). 如果您不希望精灵在绕旋转方向旋转时旋转,请在精灵上以相反的方向(-360度)运行另一个CCRotateBy。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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