SKAction之后的removeFromParent

时间:2014-05-03 00:50:16

标签: ios objective-c sprite-kit

我试图在SKSpriteNode出现后删除我的shootA SKAction,但如果我这样做,它似乎会在动作之前触发。

如何在一次展示后将其删除?

这是我的代码:

SKTexture* shootTexture1 = [SKTexture textureWithImageNamed:@"shoot-b"];
shootTexture1.filteringMode = SKTextureFilteringNearest;

SKTexture* shootTexture2 = [SKTexture textureWithImageNamed:@"shoot-a"];
shootTexture2.filteringMode = SKTextureFilteringNearest;

SKAction* flap = [SKAction repeatAction:[SKAction animateWithTextures:@[shootTexture1, shootTexture2, ] timePerFrame:0.1] count:1];

SKSpriteNode *shootA = [SKSpriteNode spriteNodeWithTexture:shootTexture1];
[shootA setScale:1.0];
shootA.position = CGPointMake(dragon.position.x+40, dragon.position.y-10);
shootA.size = CGSizeMake(shootA.size.width/8, shootA.size.height/8);

[shootA runAction:flap withKey:@"shootGo"];

[self addChild: shootA];

1 个答案:

答案 0 :(得分:2)

您可以将SKAction更改为序列,然后将removeFromParent添加到结尾 -

SKAction* flap = [SKAction sequence:@[
                                     [SKAction repeatAction:[SKAction animateWithTextures:@[shootTexture1, shootTexture2, ] timePerFrame:0.1] count:1],
                                     [SKAction removeFromParent]
                                     ]];