我想在我的spriteNode上运行两个动画,具体取决于它的旋转。如果值为负,则运行其中一个动画,如果它是正向运行另一个动画。我设法做到了(有点),但我遇到了问题。如果Animation1正在运行,并且zRotation变为正数,则它们都会运行,因为它们会永远重复。所以我这样做了:
NSMutableArray *walkingTextures = [NSMutableArray arrayWithCapacity:14];
for (int i = 1; i < 15; i++) {
NSString *textureName =
[NSString stringWithFormat:@"character%d", i];
SKTexture *texture =
[SKTexture textureWithImageNamed:textureName];
[walkingTextures addObject:texture];
}
SKAction *spriteAnimation = [SKAction animateWithTextures:Textures timePerFrame:0.04];
repeatWalkAnimation = [SKAction repeatActionForever:spriteAnimation];
[sprite runAction:repeatWalkAnimation withKey:@"animation1"];
然后当我希望它停止时:
[self removeActionForKey:@"animation1"];
但它继续运行动作,我该如何停止动作呢?谢谢!
答案 0 :(得分:17)
该方法应该在运行SKAction的节点上调用。
更改
[self removeActionForKey:@"animation1"];
到
[sprite removeActionForKey:@"animation1"];