18

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?

Matthijn
  • 3,126
  • 9
  • 46
  • 69
  • Action Timing Modes are listed under constants guess we stuck with what apple has for now – DogCoffee Oct 01 '13 at 07:39
  • 1
    I think you should use a custom action for that.Also I think your question is already answered on this thread http://stackoverflow.com/questions/19026895/how-to-apply-different-easing-effects-to-sprite-action – lionserdar Nov 05 '13 at 15:58
  • Does anyone know how to completely turn off easing on an SkAction? I would think this to be quite an important property but maybe not... – ObjectiveCsam Dec 26 '14 at 01:09
  • @ObjectiveCsam - "linear" is no easing (ie, it moves from point a to point b linearly rather than more slowly at the start or end). – Tom Dibble Jul 28 '18 at 23:31

3 Answers3

15

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
Sam Keene
  • 297
  • 2
  • 10
11

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

Alexis Taugeron
  • 161
  • 1
  • 5
0

Here is fresh, as spring water, answer goes. In iOS 8 timingFunction was introduced. It allows you to create custom timing curves.

The return SKActionTimingFunction value of the timing function determines the actual time used to perform the animation.

This way, you can implement your own easing function. Although it has certain limitations: output values must be between 0.0 and 1.0. So for more realistic elastic bouncing I would recommend use SpriteKit-Spring

kelin
  • 11,323
  • 6
  • 67
  • 104