停止重复的 SKAction - Sprite Kit [英] Stop SKAction that RepeatsForever - Sprite Kit

查看:32
本文介绍了停止重复的 SKAction - Sprite Kit的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想根据 spriteNode 的旋转在我的 spriteNode 上运行两个动画.如果值为负,则运行其中一个动画,如果值为正,则运行另一个.我设法做到了(有点)但我遇到了问题.如果 Animation1 正在运行,并且 zRotation 变为正值,则它们都会运行,因为它们将永远重复.所以我这样做了:

I want to run two animations on my spriteNode depending on its rotation. If the value is negative run one of the animations, if it's positive run the other. And I managed to do that (kind of) but I have a problem. If Animation1 is running, and zRotation changes to positive, they both run because they are repeating forever. So I did this :

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

然后当我想要它停止时:

and then when I want it to stop :

    [self removeActionForKey:@"animation1"];

但是它一直在运行动作,那么我如何停止动作呢?谢谢!

but it keeps running the action, how can I stop the action, then? Thank you!

推荐答案

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

The method is supposed to be called on the node which the SKAction is running on.

改变

[self removeActionForKey:@"animation1"]; 

[sprite removeActionForKey:@"animation1"]; 

这篇关于停止重复的 SKAction - Sprite Kit的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆