是否可以在 SKAction 中途结束? [英] Is it possible to end an SKAction mid-action?

查看:17
本文介绍了是否可以在 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;
        }];

我想知道是否有可能做到这一点,如果 MonsterNode 到达 iOS 设备屏幕的边界,它实际上会停止运行该操作.我目前在屏幕边缘有 SKSpriteNode 边界,与联系代表链接以通知怪物和墙壁是否接触.但是,如果我不能真正阻止怪物的 actionMove 动作完成,那将毫无意义.怪物需要停在屏幕的边界.如果无法在 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天全站免登陆