是否有可能结束SKAction中期行动? [英] Is it possible to end an SKAction mid-action?

查看:75
本文介绍了是否有可能结束SKAction中期行动?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个SKSpriteNode(monsterNode)的子类。它会自动在屏幕上运行,使用矢量跟随播放器。我目前正在使用以下操作来使它运行:

I have a subclass of SKSpriteNode (monsterNode). It automatically runs around the screen using vectors to follow the player. I am currently using the following action to make it run around:

SKAction *actionMove = [SKAction moveTo:actualDistance duration:time];
        [self runAction:actionMove completion:^ {
            _currentState = SVGMonsterStateIdle;
        }];

我想知道它是否有可能使它如此怪物节点实际上STOPS运行动作如果它击中了iOS设备屏幕的边界。我目前在屏幕边缘有SKSpriteNode边界,与联系代表链接,以通知怪物和墙壁是否接触。但是,如果我无法实际阻止怪物的动作移动到完成,那就没有任何意义。怪物需要停在屏幕的边界。如果无法在执行中停止SKAction,是否有迂回的方法呢?

I am wondering if its possible to make it so the monsterNode actually STOPS running the action if it hits the boundary of the iOS device screen. I currently have SKSpriteNode boundaries on the edges of the screen, linked with a contact delegate to notify if the monster and walls make contact. However, that means nothing if I can't actually stop the monster's actionMove action from going to completion. The monster needs to stop at the boundaries of the screen. If it is not possible to stop an SKAction mid-execution, is there a roundabout way to do so?

推荐答案

看看 SKNode.h 头文件 - 它列出了两个函数:

Look at the SKNode.h header file - it has two functions listed:

- (void)removeActionForKey:(NSString *)key;
- (void)removeAllActions;

后者将起作用: [monsterNode removeAllActions];

这篇关于是否有可能结束SKAction中期行动?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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