Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

swift animate spritekit with damping effect

I've been searching on the internet for several days, I didn't find what I'm looking for. I'm working on an iOS game and I would like to move some sprites using usingSpringWithDamping (to have some rubber effect when moving my sprites).

I have found many solutions for UIViews but nothing for SKSpriteNode.

I would like to move a SKSpriteNode from position 1 to position 2 with a Damping effect.

Can you please give me some ideas? Thanks.

C.C.

like image 662
CC. Avatar asked Sep 07 '17 19:09

CC.


2 Answers

The Sprite Kit Utils from Ray Wenderlich (https://github.com/raywenderlich/SKTUtils) could be what you are looking for. Specifically, using SKTEffects and SKTTimingFunctions will allow you to add easing to your SKActions.

For example SKTTimingFunctionElasticEaseIn, SKTTimingFunctionElasticEaseOut, and SKTTimingFunctionElasticEaseInOut have the rubber effect you are looking for, but you may need to tweak them to your needs. Ray's utils also have other easing functions available; there is a good reference on different easing functions at: http://easings.net

Hope this helps!

like image 92
JohnV Avatar answered Nov 16 '22 04:11

JohnV


UIView animations have support for spring animations, but these are not available in SpriteKit.

There is a third-party library on GitHub which extends SKAction with spring animations: https://github.com/ataugeron/SpriteKit-Spring

like image 4
nathangitter Avatar answered Nov 16 '22 06:11

nathangitter