Scroll for SpriteKit

1

I'm making a game with Swift, and I have a giant image in a SKSpriteNode that is the map (similar to the image I attached) and each point is a SKSpriteNode child, I'm doing the scroll in this way in the touchesMoved function:

let newLocation = touch.locationInNode(self)
let prevLocation = touch.previousLocationInNode(self)
var newYPosition = map.position.y
if (newLocation.y > prevLocation.y) { newYPosition = map.position.y + abs(newLocation.y - prevLocation.y) }
else if newLocation.y < prevLocation.y { newYPosition = map.position.y - abs(newLocation.y - prevLocation.y) }
if newYPosition <= 0 && newYPosition > self.frame.height - map.frame.height{ map.position.y = newYPosition }

But when doing it this way the scroll is slow, it does not have the effect that it stops slowly when I release it, if not that it stops immediately when I take out my finger. How can I do to have something more similar to a real scroll?

    
asked by albertcito 29.04.2016 в 00:31
source

1 answer

0

Here is the answer:

link

When I raise my finger slowly, then the scrolling stops, but when I raise my finger quickly the scroll moves a bit more and stops a little bit further.

    
answered by 30.04.2016 / 23:19
source