SpriteKit SKAction缓动 [英] SpriteKit SKAction easing
问题描述
我发现这个工作原理:
SKAction * moveAction = [SKAction moveByX:moveX y:moveY duration:0.5];
moveAction.timingMode = SKActionTimingEaseInEaseOut;
[node runAction:moveAction];
但是只有几种缓动类型可用 ,即Linear,EaseIn,EaseOut,EaseInOut。
这些缓动值是固定的,不能更改。我正在寻找类似EleasticInOut的东西。优选地具有更多的控制。
我一直在使用SKEase框架:
https://github.com/buddingmonkey/SpriteKit-Easing
它像标准的SpriteKit操作一样简单,并添加所有通常更复杂的缓动,立方体,反弹,弹性,背面等。
SpriteKitUtils还添加了更复杂的缓动类型和一些方便的SpriteKit实用程序: https: //github.com/raywenderlich/SKTUtils
另一个选项是使用自定义操作方法滚动您自己的方法,并传递一段代码您的自定义缓动/动画函数:
- (SKAction *)customActionWithDuration:(NSTimeInterval)seconds actionBlock: SKNode * node,CGFloat elapsedTime))block
Well the title gives the question away, how can I apply easing to the SKAction node actions in SpriteKit?
I found that this works:
SKAction *moveAction = [SKAction moveByX:moveX y:moveY duration:0.5];
moveAction.timingMode = SKActionTimingEaseInEaseOut;
[node runAction:moveAction];
However there are only a few easing types available there, namely Linear, EaseIn, EaseOut, EaseInOut.
And those easing values are fixed and cannot be altered. I am looking for something like EleasticInOut. With preferably a bit more control. How can I create that?
I've been using the SKEase framework: https://github.com/buddingmonkey/SpriteKit-Easing It's as simple to use as the standard SpriteKit Actions and adds all the usual more complex eases, cubic, bounce, elastic, back etc. SpriteKitUtils also adds more complex easing types and some handy SpriteKit utilities: https://github.com/raywenderlich/SKTUtils
The other option is to roll your own using the custom action method, and pass it a block of code with your custom easing/animation function:
-(SKAction *)customActionWithDuration:(NSTimeInterval)seconds actionBlock:(void (^)(SKNode *node, CGFloat elapsedTime))block
这篇关于SpriteKit SKAction缓动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!