Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SpriteKit SKAction easing

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?

like image 242
Matthijn Avatar asked Sep 30 '13 13:09

Matthijn


2 Answers

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
like image 123
Sam Keene Avatar answered Nov 20 '22 03:11

Sam Keene


Apple introduced spring animations in UIKit a couple years ago, by letting you set a spring damping and initial velocity when performing a UIView animation. Unfortunately they didn't implement that in SpriteKit, so I made my own library that does just that.

It's a set of extensions on SKAction that replicate most factory methods, adding the damping and velocity parameters.

The code is on GitHub, feel free to use it: https://github.com/ataugeron/SpriteKit-Spring

like image 38
Alexis Taugeron Avatar answered Nov 20 '22 04:11

Alexis Taugeron