问题
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") }) ]))
The last skaction does not get called.
But when I remove the second waitForDuration, the last skaction gets called.
self.runAction(SKAction.sequence([ SKAction.waitForDuration(1), SKAction.runBlock({ self.speed = 0; print("pause") }), SKAction.runBlock({ self.speed = realSpeed; print("resume") }) ]))
What is happening here?
回答1:
A node's speed
property affects the execution speed of actions run on that node. From the docs,
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.
In your first runBlock
, you are setting the speed
property of self
to 0. This causes the second waitForDuration
action to run infinitely slow (assuming actualDuration = duration/speed
).
来源:https://stackoverflow.com/questions/32485107/skaction-waitforduration-blocking-skaction-sequence