开发者

Shooting bullets with a joystick cocos2d

开发者 https://www.devze.com 2023-03-21 23:39 出处:网络
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开发者_如何学JAVA joystick is pointing. I have the player mov

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开发者_如何学JAVA 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.


You should get the angle from joystick. For instance, SneakyInput has a degrees property which enables you to rotate your bullets like this :
_bullet.rotation = -joystick.degrees;

And your update method can be like this :

void update:(ccTime) delta
{
    float moveAngle = _bullet.rotation;
    CGPoint deltaPos = CGPointMake(cos(moveAngle) * velocity, sin(moveAngle) * velocity);
    _bullet.position = ccpAdd(self.position, deltaPos);
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号