ios - 在 SKAction 之后移除 FromParent

标签 ios objective-c sprite-kit

我试图在 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];

最佳答案

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

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

关于ios - 在 SKAction 之后移除 FromParent,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23438991/

相关文章:

iOS:检测包含多个图像的 UIImageView 中的图像触摸

ios - 使用检索到的核心数据

ios - SWRevealViewController 不切换

iphone - 进入后台取消剩余请求

ios - Xcode swift : how to import a Swift project

ios - 用 SpriteKit 定制的数字替换数字

ios - 离开屏幕后删除节点

ios - 在两个局部变量之间的仪器中检测到泄漏

objective-c - 使用循环以编程方式添加 NSMutableArray 时出错

ios - 表格 View 单元格背景没有完全改变