I have a sprite node on the screen, that the player is able to move left and right. I know how to make it move left and right using touchesMoved, however, if the player touches a location the node snaps to that location. For example, if the node was on the left side of the screen, and the player touched the right side of the screen, the node would immediately move to the touch location. I don't want this behavior. I only want to the node to move when the player is moving their finger left or right, not when they touch a location. Below is the code I currently use. There isn't any code that would affect the playerNode x position in the touchesBegan or touchesEnded function.
override func touchesMoved(_ touches: Set<UITouch>, with event: UIEvent?) {
for touch in touches
{
if game.state == .game
{
let position = touch.location(in: playableArea)
game.playerNode.position.x = position.x
}
}
}
How can I stop this behavior from happening, and only have the node move when the players finger is moving left or right?