My Code:
-(void)ShootingWithJoystick {
if (_nextProjectile != nil) return;
CGPoint location = CGPointMake(rightJoystick.velocity.x,rightJoystick.velocity.y);
// Set up initial location of projectile
_nextProjectile = [[CCSprite spriteWithFile:@"player.png"] retain];
_nextProjectile.scale = 0.2f;
_nextProjectile.position = player.position;
// Determine the angle to rotate
CGPoint shootVector = ccpSub(location, player.position);
// Move projectile offscreen
ccTime delta = 1.0f;
CGPoint normalizedShootVector = ccpNormalize(shootVector);
CGPoint overshotVector = ccpMult(normalizedShootVector, 420);
[_nextProjectile runAction:[CCSequence actions:
[CCMoveBy actionWithDuration:delta position:overshotVector],
[CCCallFuncN actionWithTarget:self selector:@selector(spriteMoveFinished:)],
nil]];
// Actually set up the actions
[player runAction:[CCSequence actions:
[CCCallFunc actionWithTarget:self selector:@selector(finishShoot)],
nil]];
// Add to projectiles array
_nextProjectile.tag = 2;
}
- (void)finishShoot {
// Ok to add now - we've finished rotation!
[self addChild:_nextProjectile];
[_projectiles addObject:_nextProjectile];
// Release
[_nextProjectile release];
_nextProjectile = nil;
NSLog(@"finishShoot");
}
-(void)spriteMoveFinished:(id)sender {
CCSprite *sprite = (CCSprite *)sender;
[self removeChild:sprite cleanup:YES];
if (sprite.tag == 2) { // projectile
NSLog(@"spriteMoveFinsished");
[_projectiles removeObject:sprite];
}
}
The ShootingwithJoystick method is very time call when my rightJoystick is active. My leftJoystick moves the player and the rightjoystick rotates the player and shoots in that direction but when i test it the bullet just goes in only one direction (bottom left corner) and if i want to shoot up it shoot still in the bottom left corner
Can you help me please?