Animation 动画的最后一帧保留在屏幕上(SKTextureAtlas、SpriteKit)

Animation 动画的最后一帧保留在屏幕上(SKTextureAtlas、SpriteKit),animation,ios7,sprite-kit,Animation,Ios7,Sprite Kit,从SpriteKit开始。可能是因为我是一个初学者,我缺少一些非常基本的东西,但我的这部分代码有问题 我正在创建一帧一帧的爆炸动画。我将原始节点移除为一个球,并在其位置启动此explosionParent方法,因为它的大小远大于原始对象。在里面我创建了一个SKSpriteNode,然后在上面运行动画。完成后,我检查动画是否完成,如果是这种情况,我将擦除explosionParent节点 爆炸显示在适当的位置并平稳运行,但动画的最后一帧仍保留在屏幕和节点本身上。我做错了什么?我想我是在混合概念,但

从SpriteKit开始。可能是因为我是一个初学者,我缺少一些非常基本的东西,但我的这部分代码有问题

我正在创建一帧一帧的爆炸动画。我将原始节点移除为一个球,并在其位置启动此explosionParent方法,因为它的大小远大于原始对象。在里面我创建了一个SKSpriteNode,然后在上面运行动画。完成后,我检查动画是否完成,如果是这种情况,我将擦除explosionParent节点

爆炸显示在适当的位置并平稳运行,但动画的最后一帧仍保留在屏幕和节点本身上。我做错了什么?我想我是在混合概念,但我认为在这里分享这将是一个很好的体验。提前谢谢

-(void) explosionParent:(float)positionX and:(float)positionY {

SKSpriteNode *explosionParent = [SKSpriteNode spriteNodeWithImageNamed:@"Explosion 1"];

explosionParent.name = @"explosionParent";
explosionParent.position = CGPointMake(positionX,positionY);

[self addChild:explosionParent]; // Creating child for the explosion


// Starting animation

SKTextureAtlas *atlas = [SKTextureAtlas atlasNamed:@"RedExplosion"];

SKTexture *explosion1 = [atlas textureNamed: @"explosion-1-Red.png"];
SKTexture *explosion2 = [atlas textureNamed: @"explosion-2-Red.png"];
SKTexture *explosion3 = [atlas textureNamed: @"explosion-3-Red.png"];
SKTexture *explosion4 = [atlas textureNamed: @"explosion-4-Red.png"];
SKTexture *explosion5 = [atlas textureNamed: @"explosion-5-Red.png"];
SKTexture *explosion6 = [atlas textureNamed: @"explosion-6-Red.png"];
SKTexture *explosion7 = [atlas textureNamed: @"explosion-7-Red.png"];

NSArray *atlasTextures = @[explosion1,explosion2,explosion3,explosion4,explosion5,explosion6,explosion7];

SKAction *explosionAnimation = [SKAction animateWithTextures:atlasTextures timePerFrame:1.0f/30.0f];


[explosionParent runAction:explosionAnimation] ;  // launching the animation itself


// Killing the explosion node if the action has finished

if (![explosionParent hasActions])   
{
    [explosionParent removeFromParent];
}

}

你的问题是如果![explosionParent hasActions],它尚未完成其操作。相反,你应该考虑的是把一些动作链接在一起,一个做动画,然后从它的父节点上移除这个节点。您可以使用+SKAction*序列:NSArray*操作来执行此操作

非常感谢,@InkGolem!我的问题是我不知道我可以将removeFromParent作为SKAction调用:SKAction*removeExplosion=[SKAction removeFromParent];。你给了我线索,非常感谢!