简体   繁体   English

Swift Pause Endless SKAction

[英]Swift Pause Endless SKAction

I am currently making a flappy bird clone, and have a SKAction (runActionForever) in my didMoveTOView method. 我目前正在制作一个蓬松的鸟类克隆,并且在didMoveTOView方法中有一个SKAction(runActionForever)。 However, once I die, I want to terminate that action, by which is followed a popup screen. 但是,一旦我死了,我想终止该动作,然后弹出一个屏幕。

override func didMoveToView(view: SKView) {
     var endlessAction = SKAction.runActionForever(spawn, delay)
 }

 func died() {
     endlessAction..... ?
     screenDied.position = CGPoint(self.frame.x / 2, self.frame.y / 2)
     addChild(screenDied)
 }

Now, in another function, died(), how do I end this action? 现在,在另一个函数die()中,如何结束此动作? - so I can then make a screen popup. -这样我就可以弹出屏幕了。

Thanks! 谢谢!

SKAction Class Reference : http://goo.gl/w6ZEFI SKAction类参考: http : //goo.gl/w6ZEFI

SKNode Class Reference : http://goo.gl/Wn9xGw SKNode类参考: http : //goo.gl/Wn9xGw

Adding Actions to Nodes : http://goo.gl/xR9Tfb 向节点添加操作: http : //goo.gl/xR9Tfb

To cancel actions that a node is running, call its removeAllActions method. 要取消节点正在运行的操作,请调用其removeAllActions方法。 All actions are removed from the node immediately. 所有操作将立即从节点中删除。 If a removed action had a duration, any changes it already made to the node remain intact, but further changes are not executed. 如果删除的操作具有持续时间,则它对节点所做的任何更改均会保持不变,但不会执行进一步的更改。

Normally, you can't see which actions a node is executing and if you want to remove actions, you must remove all of them. 通常,您看不到节点正在执行哪些动作,并且如果要删除动作,则必须删除所有动作。 If you need to see whether a particular action is executing or remove a specific action, you must use named actions. 如果需要查看某个特定操作是正在执行还是要删除特定操作,则必须使用命名操作。 A named action uses a unique key name to identify the action. 命名动作使用唯一的键名来标识动作。 You can start, remove, find, and replace named actions on a node. 您可以在节点上启动,删除,查找和替换命名的动作。

If you need to remove all actions from your node, you can use the removeAllActions method. 如果需要从节点中删除所有操作,则可以使用removeAllActions方法。 However, if you need to remove a specific action you need to run it with the method named runAction:withKey: . 但是,如果需要删除特定操作,则需要使用名为runAction:withKey:的方法来运行它。

If an action with the same key is already running, it is removed before the new one is added. 如果具有相同键的操作已在运行,则在添加新键之前将其删除。

Also, you can use actionForKey: to see if an action is running on a specific node. 另外,您可以使用actionForKey:来查看某个动作是否正在特定节点上运行。

Then use removeActionForKey: to remove the action. 然后使用removeActionForKey:删除操作。

PS : If you're looking to pause the actions and the node itself, you might want to look for the paused property on your node. PS:如果您要暂停动作和节点本身,则可能要在节点上寻找被paused属性。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM