我有这种方法让我的AI用来射击玩家。当AI机器人被杀死时,它会自行调用[self removeAllActions]。此操作的引用(self.shootAction)也设置为nil。然而,一旦机器人死亡并等待重生,射弹仍然会发射。我的猜测是这个方法在机器人被杀之前被调用。那时机器人是隐形的和不活跃的。有没有办法阻止这些操作或runBlocks执行?我尝试使用弱自我引用,但这没有做任何事情。
- (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;
}