How to change duration of executed SpriteKit action

廉价感情. 提交于 2019-12-22 16:58:07

问题


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?


回答1:


Make sequence an ivar or property. Then at any time you can do this to slow it down:

sequence.speed = 0.5;



回答2:


Accepted answer doesn't work for me. My solution is to stop current animation and run it again with needed speed:

    removeAllActions()
    sequence.speed = 100 // run 100 times faster
    run(anim)


来源:https://stackoverflow.com/questions/23314691/how-to-change-duration-of-executed-spritekit-action

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!