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?