如何更改执行的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屋!