2

In a game I'm developing with SpriteKit, I want certain objects to appear and shrink. I already know how to scale them down, and I'm achieving this using the following code:

myNode.run(SKAction.scale(to: 0, duration: 3))

However, the shrinking happens 'linearly'. Is there a way to make it shrink exponentially faster? Or at least that it starts slowly and at the last second it shrinks twice as fast?

Gabe12
  • 607
  • 1
  • 7
  • 25
  • Try with easing modes. But I doubt it will give you a desired result. There are 3rd parties though... So you can try them out. Or maybe you can try with a custom action... – Whirlwind Apr 10 '17 at 18:54
  • This may be what you're looking for http://stackoverflow.com/questions/40043177/easeout-action-with-custom-skaction – 0x141E Apr 11 '17 at 16:42

2 Answers2

0

Sorry I could not test this out, I do not have a compiler. It is properly not the best way to do it, but I gave it a shot:

 func delay(_ delay:Double, closure:@escaping ()->()) {
        let when = DispatchTime.now() + delay
        DispatchQueue.main.asyncAfter(deadline: when, execute: closure)
    }

let totalRunTime = 1
var add = 0.0
var scale = 1
var done = false
while !done{
 delay(add, closure: {
add += 0.1
scale = 1 - (add ^2)
myNode.run(SKAction.scale(to: scale, duration: totalRunTime / 10))
})
if add == 0{
done = true
}
}

Edit: When I look at my code I may see a bug: maybe you need to switch the exponential formula from scale to duration to make it work, I can not test it now :(

J. Doe
  • 12,159
  • 9
  • 60
  • 114
0

Have a look at the Sprite Kit Utils from Ray Wenderlich. It's quite a useful library and also provides easing functions for movement, scale, and rotate actions.

(For reference, have a look at the different easing functions demonstrated on easings.net)

Hope that helps!

JohnV
  • 981
  • 2
  • 8
  • 18