简体   繁体   English

SKAction不会永远重复

[英]The SKAction does not repeat forever

The bellow code is not repeating inspite of explicitly setting the SKAction as repeatActionForever. 尽管显式将SKAction设置为repeatActionForever,但下面的代码没有重复。

SKAction *action = [SKAction moveToY:self.frame.size.height + bullet.size.height duration:2];
SKAction *remove = [SKAction removeFromParent];
SKAction *fireForever = [SKAction repeatActionForever:[SKAction sequence:@[action,remove]]];
[bullet runAction:fireForever];

The bullet just fires once , when its expected to be fired every 1 second. 子弹只发射一次,而预期每1秒钟发射一次。

You are removing the bullet from the parent, that's why it's not firing again, What you should do is create a method to create a bullet - fire it - destroy it, and create an SKAction that uses this method. 您正在从父级中删除子弹,这就是为什么它不会再次发射。您应该做的是创建一个方法来创建子弹-发射它-销毁它,并创建一个使用此方法的SKAction。

-(void)FireBullet
{
    //create bullet
    //fire it
    //remove from parent
}

and add the following code when you want the bullets to start firing. 并在您希望子弹开始发射时添加以下代码。

SKAction *myAction = [SKAction performSelector:@selector(FireBullet) onTarget:self];
SKAction *forever = [SKAction repeatActionForever:myAction];
[self runAction:forever];

Hope this helps, let me know if you need more help. 希望这会有所帮助,如果您需要更多帮助,请告诉我。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM