SpriteKit SKAction缓和

Mat*_*ijn 15 cocoa-touch ios

好吧标题提出了问题,我如何将缓动应用于SpriteKit中的SKAction节点操作?

我发现这有效:

SKAction *moveAction = [SKAction moveByX:moveX y:moveY duration:0.5];
moveAction.timingMode = SKActionTimingEaseInEaseOut;
[node runAction:moveAction];
Run Code Online (Sandbox Code Playgroud)

不过也有只提供一些缓和的类型存在,即线性,EaseIn,EaseOut,EaseInOut.

这些缓和值是固定的,不能改变.我正在寻找像EleasticInOut这样的东西.最好有一点控制.我该如何创建呢?

小智 15

我一直在使用SKEase框架:https: //github.com/buddingmonkey/SpriteKit-Easing 它与标准的SpriteKit动作一样简单,并添加了所有通常更复杂的缓动,立方体,弹跳,弹性,背部等. SpriteKitUtils还添加了更复杂的缓动类型和一些方便的SpriteKit实用程序:https://github.com/raywenderlich/SKTUtils

另一个选项是使用自定义操作方法自行滚动,并使用自定义缓动/动画功能传递一段代码:

-(SKAction *)customActionWithDuration:(NSTimeInterval)seconds actionBlock:(void (^)(SKNode *node, CGFloat elapsedTime))block
Run Code Online (Sandbox Code Playgroud)


小智 11

Apple在几年前在UIKit中引入了弹簧动画,让你在执行UIView动画时设置弹簧阻尼和初始速度.不幸的是他们没有在SpriteKit中实现它,所以我创建了自己的库来做到这一点.

它是SKAction上的一组扩展,它复制了大多数工厂方法,添加了阻尼和速度参数.

代码在GitHub上,随意使用它:https://github.com/ataugeron/SpriteKit-Spring