【发布时间】:2011-12-12 18:56:37
【问题描述】:
这确实很麻烦,但我有两个精灵,它们都是 17 像素长的手臂。它们都在 ccp(0.5f,0.0f) 处有锚点;我想要的是,当 arm1 旋转时,arm2 的 CGPoint 等于 arm1 锚点的另一端。比如,在 45 度角,CGPoint 就是 ccp (arm1.position.y, arm1.position.x + 17);
所以我在 ccTime 函数中更新了 arm1 的旋转,它调用了另一种方法来计算角度旋转。基本上发生的事情是...... arm2 在正确的圆形区域内快速旋转,这意味着某些事情是正确的,但旋转速度非常快。
-(void) callEveryFrame:(ccTime)dt{
//if the user is holding down on the screen, arm1 rotates.
if(held == true){
_theArm2.position = [self fixAngle];
timer = timer + .0166; //this gets reset after touchesEnded.
_theArm1.rotation = _theArm1.rotation - (timer * 10);
}
-(CGPoint)fixAngle{
CGFloat theAngle = _theArm1.rotation;
//I'm not to sure how the degrees works in cocos2d, so I added 90 to the angle of rotation's original position, and it works until the rotation variable changes.
CGFloat thyAngle = theAngle + 90;
CGFloat theMathx = (17*cosf(thyAngle)); //17 is the length of the arm
CGFloat theMathy = (17*sinf(thyAngle));
theMathx = theMathx + 100;//these 2 updates just change the position, because arm1's
theMathy = theMathy + 55; //CGpoint is located at ccp(100,57)
return CGPointMake(theMathx, theMathy);
}
对不起,如果代码是......不好。我对编程比较陌生,但是除了愚蠢的 arm2 喜欢快速旋转一圈之外,一切都可以正常工作。
我会爱任何在我/他们的余生中解决我问题的人。
【问题讨论】:
-
我认为旋转是弧度,而不是度数。我从那里开始。
标签: objective-c xcode math cocos2d-iphone geometry