【问题标题】:removeFromParent after SKAction在 SKAction 之后 removeFromParent
【发布时间】:2014-05-03 14:28:56
【问题描述】:

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

展示过一次后如何移除它?

这是我的代码:

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];

【问题讨论】:

    标签: ios objective-c sprite-kit


    【解决方案1】:

    您可以将您的 SKAction 更改为一个序列,然后将 removeFromParent 添加到末尾 -

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-04-30
      • 1970-01-01
      • 2023-03-16
      • 1970-01-01
      相关资源
      最近更新 更多