Sprite kit 向目标发射射弹的精灵套件

Sprite kit 向目标发射射弹的精灵套件,sprite-kit,Sprite Kit,我想让我的炮塔精灵向怪物射击。我已经让炮塔转向怪物并跟随它直到它超出射程,现在我只需要让射击发生 从炮塔向怪物发射炮弹的最佳方式是什么 我已经完成了这部分: -(void)shoot { SKSpriteNode *bullet = [SKSpriteNode spriteNodeWithImageNamed:@"CannonMissile-hd.png"]; ... i don't know what to do next } 而且,我需要它每隔x秒拍摄一次 谢谢 -(void)

我想让我的炮塔精灵向怪物射击。我已经让炮塔转向怪物并跟随它直到它超出射程,现在我只需要让射击发生

从炮塔向怪物发射炮弹的最佳方式是什么

我已经完成了这部分:

-(void)shoot
{
     SKSpriteNode *bullet = [SKSpriteNode spriteNodeWithImageNamed:@"CannonMissile-hd.png"]; ... i don't know what to do next

}
而且,我需要它每隔x秒拍摄一次

谢谢

-(void)shoot
{
    SKSpriteNode *turretNode;//I assume you have this node already in the scene . Dont use this line
    SKSpriteNode *enemy;//I assume you have this node already in the scene . Dont use this line
    SKSpriteNode *bullet = [SKSpriteNode spriteNodeWithImageNamed:@"CannonMissile-hd.png"];
    bullet.zPosition = turretNode.zPosition -1;//if you want your bullet not to spawn on top of your turret
    [turretNode addChild:bullet];
    //you need to set the physics body of the bullet so you can detect contacts
    SKAction *move = [SKAction moveTo:enemy.position duration:0.5];//if u have multiple enemies then you have to deceide which one to hit
    [bullet runAction:move completion:^{
        [bullet removeFromParent];//removes the bullet when it reaches target
        //you can add more code here or in the didBeginContact method
    }];
    //repeat the process
    [self performSelector:@selector(shoot) withObject:nil afterDelay:5];//replace 5 with ur x seconds
    //that's it
}