我想根据其旋转在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"];

但它会继续执行操作,那么我该如何停止操作?谢谢!

最佳答案

该方法应该在运行SKAction的节点上调用。

更改

[self removeActionForKey:@"animation1"];


[sprite removeActionForKey:@"animation1"];

08-07 04:07