2011-04-20 93 views
0

我有这样的:如何获得速度的角度来旋转子弹?

CGPoint vel = hudLayer.rightJoystick.velocity; 

      CCBullet* sp = [CCBullet spriteWithFile:@"green.png"]; 
      sp.position = player.position; 
      [self addChild:sp z:-10]; 

      vel = ccpMult(ccpNormalize(vel), 300); 
sp.rotation = //how to get the rotation out of the velocity? 

任何帮助吗?

回答

6
float angle = atan2f(vel.y, vel.x); 
+0

谢谢工作,但我需要做到这一点:sp.rotation = CC_RADIANS_TO_DEGREES(-1 * angle); – cocos2dbeginner 2011-04-20 11:59:39

+0

是的,我应该可能已经解释过这会给你一个弧度(0 .. pi * 2)而不是度数(0 .. 360) – 2011-04-20 12:00:47