I'm making a game with Swift, and I have a giant image on a SKSpriteNode
map (similar to the image I attached) and each point is a SKSpriteNode
child, I'm scrolling like this in the function touchesMoved
:
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 by doing it this way the scroll is slow, it doesn't have the effect that it slows down when I release it, but it stops immediately when I release my finger. How can I do to have something more similar to a real scroll?
Here is the answer:
https://www.raywenderlich.com/96822/sprite-kit-tutorial-drag-drop-sprites
When I lift my finger slow then it stops scrolling, but when I lift my finger fast it scrolls a bit further and stops a bit later.