0

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.

mad_manny
  • 1,081
  • 16
  • 28

1 Answers1

0

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);
}
Baris Atamer
  • 700
  • 7
  • 13