Is it possible to end an SKAction mid-action?

僤鯓⒐⒋嵵緔 提交于 2019-11-29 11:06:21

问题


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

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?


回答1:


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

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

The latter will work: [monsterNode removeAllActions];



来源:https://stackoverflow.com/questions/19041610/is-it-possible-to-end-an-skaction-mid-action

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!