Reputation: 161
Hi I'm making a game in Swift with Sprite Kit and I'm wondering if there is a way to have a sprite have smooth movement. Currently I'm using the moveTo method in SKAction and the sprite gets to the target location in a set period of time - meaning that if the location is farther away, the sprite will get there faster. I'm wondering if there is a solid way of getting the sprite to accelerate to a maximum set speed and then slow down when getting to the location. All help is appreciated.
Upvotes: 2
Views: 1691
Reputation: 8828
Use the Pythagorean theorem to get the correct duration based on distance in order to get desired speed. See here: https://stackoverflow.com/a/19126642/431271
as far as slowing at the end goes, you can do some quick built in easing methods like this:
var moveAction = SKAction.moveByX(moveX, y:moveY, duration:0.5);
moveAction.timingMode = SKActionTiming.EaseInEaseOut
node.runAction(moveAction)
And if you want other easing methods use libraries such as the one referenced here
Upvotes: 4