将CCSprite移动到另一个CCSprite圆形 [英] Move CCSprite around another CCSprite Circle Shape
问题描述
我想要达到的目的是:
我们有CCSprite Circle A和CCSprite Circle B.
We have CCSprite Circle A and CCSprite Circle B.
我已经尝试创建一个CCNode并附加圆圈B到它。在这种情况下,它工作完美,但位置也是恒定的。我需要移动圆周围A和更新位置。我将在屏幕上有更多的对象,我将检查B是否与其他对象相交,但是对于这种情况,我需要在旋转时更新位置。非常感谢你的帮助家伙。我使用Cocos2D v3.0
Move Circle B around Circle A. I already tried to create a CCNode and attach the circle B to it. In this case it works perfectly but the position is constant also. I need to move the circle around A and update the position. I will have more objects on the screen and I will check if B intersect some other objects, but for that case I need to update the position while rotating. Much appreciate your help guys. I am using Cocos2D v3.0
推荐答案
也许这样吗?将其放在您的更新方法中。我在我的box2d项目中使用这个代码进行轨道。根据您的需要更改它。
Maybe something like this? Put this in your update method. I used this code in my box2d project for orbit. Change it for your needs.
b2Vec2 center = bodyA->GetPosition();
int smoothness = 1000;
int radius = 100;
for (int i = 0; i < smoothness; i++) {
float angle = (i / smoothness) * 360 * DEGTORAD;
b2Vec2 pos( sinf(angle), cosf(angle));
b2Vec2 newposition = center + radius * pos;
bodyB->SetTransform(newposition, bodyB->GetAngle());
}
这篇关于将CCSprite移动到另一个CCSprite圆形的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!