0

我在用:

 cpVect vector1=cpv(angle, 400);

 [body applyForce:vector1 offset:vector1];

但这不能很好地使用触摸屏在用于获取角度的代码行下方放置正确的角度

-(void)ccTouchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
    for( UITouch *touch in touches )
    {
        CGPoint location = [touch locationInView: [touch view]];
        location = [[CCDirector sharedDirector] convertToGL: location];
        float angleRadians = atanf((float)location.y/ (float)location.x-1);
        float angleDegrees = CC_RADIANS_TO_DEGREES(angleRadians);
        float cocosAngle = -1 * angleDegrees;
       angle = angleDegrees + 30;
    }
}
4

1 回答 1

1

感谢大家抽出宝贵的时间为此付出。最后,我找到了在特定方向上在花栗鼠身上实现冲动的方法。现在我正在使用下面的代码。

 **angle = angle-90;                  //angle from cctouchesMoved function
 float magnitude=shootPower;        // magnitude range between 200 to 1000
 cpVect impulse = cpv((cos(angle) * magnitude) , -(sin(angle) * magnitude));

 [body applyImpulse:impulse offset:cpvzero];**

// applyImpulse 使用上述 sin 和 cos theta 值提供了根据需要放置脉冲的正确方法。

于 2013-08-08T10:32:50.227 回答