I have a working joystick in my cocos2d app but I cannot figure out how to make the 'player' shoot bullets out of it in the direction the joystick is pointing. I have the player moving and rotating. Also the bullets need to disappear when they hit the edges of the screen. Any help would be great. Thanks in advance.
问问题
635 次
1 回答
0
您应该从操纵杆获得角度。例如,SneakyInput 有一个 degree 属性,可以让您像这样旋转子弹:
_bullet.rotation = -joystick.degrees;
你的更新方法可以是这样的:
void update:(ccTime) delta
{
float moveAngle = _bullet.rotation;
CGPoint deltaPos = CGPointMake(cos(moveAngle) * velocity, sin(moveAngle) * velocity);
_bullet.position = ccpAdd(self.position, deltaPos);
}
于 2011-07-22T18:08:14.100 回答