SKAction waitForDuration() 阻塞 SKAction 序列
SKAction waitForDuration() blocking SKAction sequence
self.runAction(SKAction.sequence([ SKAction.waitForDuration(1), SKAction.runBlock({ self.speed = 0; print("pause") }), SKAction.waitForDuration(0.1), SKAction.runBlock({ self.speed = realSpeed; print("resume") }) ]))
最后一个动作没有被调用。
但是当我删除第二个 waitForDuration 时,会调用最后一个 skaction。
self.runAction(SKAction.sequence([ SKAction.waitForDuration(1), SKAction.runBlock({ self.speed = 0; print("pause") }), SKAction.runBlock({ self.speed = realSpeed; print("resume") }) ]))
这里发生了什么?
节点的 speed
属性 影响该节点上操作 运行 的执行速度。从文档中,
The default value is 1.0, which means that all actions run at their normal speed. If you set a different speed, time appears to run faster or slower for all actions executed on the node and its descendants. For example, if you set a speed value of 2.0, actions run twice as fast.
在您的第一个 runBlock
中,您将 self
的 speed
属性 设置为 0。这导致第二个 waitForDuration
操作为 运行无限慢(假设actualDuration = duration/speed
)。
self.runAction(SKAction.sequence([ SKAction.waitForDuration(1), SKAction.runBlock({ self.speed = 0; print("pause") }), SKAction.waitForDuration(0.1), SKAction.runBlock({ self.speed = realSpeed; print("resume") }) ]))
最后一个动作没有被调用。
但是当我删除第二个 waitForDuration 时,会调用最后一个 skaction。
self.runAction(SKAction.sequence([ SKAction.waitForDuration(1), SKAction.runBlock({ self.speed = 0; print("pause") }), SKAction.runBlock({ self.speed = realSpeed; print("resume") }) ]))
这里发生了什么?
节点的 speed
属性 影响该节点上操作 运行 的执行速度。从文档中,
The default value is 1.0, which means that all actions run at their normal speed. If you set a different speed, time appears to run faster or slower for all actions executed on the node and its descendants. For example, if you set a speed value of 2.0, actions run twice as fast.
在您的第一个 runBlock
中,您将 self
的 speed
属性 设置为 0。这导致第二个 waitForDuration
操作为 运行无限慢(假设actualDuration = duration/speed
)。