如何更改执行 SpriteKit 动作的持续时间 [英] How to change duration of executed SpriteKit action
问题描述
我正在执行以下 SpriteKit 操作:
I am executing the following SpriteKit action:
SKAction *moveLeft = [SKAction moveByX:-moveX y:0 duration:moveDuration];
SKAction *moveRight = [moveLeft reversedAction];
SKAction *sequence = [SKAction sequence:@[moveLeft, moveRight]];
[my_node runAction [SKAction repeatActionForever:sequence]];
我想将动作放慢几秒钟(这是由于用户点击而发生的),然后恢复正常速度.我曾尝试使用
I want to slow down the action for few seconds (this happens as a result of a user tap), and after that return to the normal speed. I have tried to do so by using
[my_node runAction [SKAction speedTo: 0.5 duration: 10]];
但它不起作用(节点在这段时间内停止而不是减速).由于对象永远在移动,我无法移除该动作并用另一个动作替换(因为它位于其路径的中间).
But it didn't work (the node halts for this duration instead of slowing down). Since the object is moving forever, I am not able to remove the action and replace with another one (since it is in the middle of its path) .
任何想法如何正确执行此操作?
Any ideas how to execute this properly?
推荐答案
将序列设为 ivar 或属性.然后你可以随时这样做来减慢速度:
Make sequence an ivar or property. Then at any time you can do this to slow it down:
sequence.speed = 0.5;
这篇关于如何更改执行 SpriteKit 动作的持续时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!