我可以将SKAction runBlock与SKNode结合使用 - runAction:completion:?功能?

时间:2021-05-13 23:08:28

when I call the runAction:completion:? function of a SKSpriteNode, and pass in a SKAction runBlock action the call back routine never gets called.

当我调用runAction时:完成:? SKSpriteNode的功能,并传入SKAction runBlock动作,回调例程永远不会被调用。

1 个解决方案

#1


2  

Well, this is possibly because SpriteKit has no way of knowing when your block actually stopped affecting the node in question. If the API was better designed maybe it'd give you a way of calling the completion from your block, but it doesn't. However, you can call whatever you'd call in the completion block yourself within your block.

好吧,这可能是因为SpriteKit无法知道您的块何时实际停止影响相关节点。如果API设计得更好,也许它会给你一种从你的块调用完成的方法,但事实并非如此。但是,您可以在块内自行调用完成块中的任何内容。

Edit: Yes, the called (in this case SpriteKit) does know when your block ends executing, but your block may perform deferred calls that will further affect the node in question, so it can't be certain the action really ended. For example, think of a block that triggers a timer that varies a certain property over time.

编辑:是的,被调用(在本例中为SpriteKit)确实知道块何时结束执行,但是你的块可能会执行延迟调用,这将进一步影响相关节点,因此无法确定操作是否真正结束。例如,考虑一个触发计时器的块,该计时器随时间变化某个属性。

#1


2  

Well, this is possibly because SpriteKit has no way of knowing when your block actually stopped affecting the node in question. If the API was better designed maybe it'd give you a way of calling the completion from your block, but it doesn't. However, you can call whatever you'd call in the completion block yourself within your block.

好吧,这可能是因为SpriteKit无法知道您的块何时实际停止影响相关节点。如果API设计得更好,也许它会给你一种从你的块调用完成的方法,但事实并非如此。但是,您可以在块内自行调用完成块中的任何内容。

Edit: Yes, the called (in this case SpriteKit) does know when your block ends executing, but your block may perform deferred calls that will further affect the node in question, so it can't be certain the action really ended. For example, think of a block that triggers a timer that varies a certain property over time.

编辑:是的,被调用(在本例中为SpriteKit)确实知道块何时结束执行,但是你的块可能会执行延迟调用,这将进一步影响相关节点,因此无法确定操作是否真正结束。例如,考虑一个触发计时器的块,该计时器随时间变化某个属性。