I have this method for my AI to use to fire upon the player. When the AI bot is killed it calls [self removeAllActions] on itself. Also the reference to the action (self.shootAction) is set to nil. However, the projectiles still fire once the bot is dead and waiting to respawn. My guess is that this method gets called just before the bot is killed. At that time the bot is invisible and inactive. Is there any way to stop these actions or runBlocks from executing? I tried using a weak reference to self, but that did nothing.
- (void)shootToward:(CGPoint)position;
{
CGPoint enemyDirection;
enemyDirection = ccpNormalize(ccpSub(position, self.position));
SKAction *wait = [SKAction waitForDuration:0.5f];
SKAction *idle = [SKAction runBlock:^{
[self idle];
}];
SKAction *walkTowardsEnemy = [SKAction runBlock:^{
[self walkWithDirection:enemyDirection];
}];
SKAction *fireAtEnemy = [SKAction runBlock:^{
[self.delegate fire:self.position
inDirection:enemyDirection owner:self projNum:0];
}];
SKAction *doneShooting = [SKAction runBlock:^{
[self doneShooting];
}];
[self idle];
self.shootAction = [SKAction sequence:@[walkTowardsEnemy, wait, idle, wait, fireAtEnemy, wait, doneShooting, idle]];
[self runAction:self.shootAction withKey:@"shootAction"];
self.shooting = YES;
}