为什么我的精灵在我向左移动时一直向右翻转?

Why my sprite keeps flipping right when I move it left?

我有一个 sprite 在向右或向左移动时缩放到 1 或 -1,如果我快速移动手指它工作正常,如果我慢慢拖动它它不会停留在左侧位置并一直向左翻转和权利。我该如何解决?这是我处理角色移动的方式:

override func touchesMoved(_ touches: Set<UITouch>, with event: UIEvent?) {
        let touch = touches.first
        if let location = touch?.location(in: self){
            player.run(SKAction.move(to: CGPoint(x:  playerPosition.x + location.x - startTouch.x, y: self.frame.height/2.5), duration: 0.1))
        }
        let touchLoc = touch!.location(in: self)
        let prevTouchLoc = touch!.previousLocation(in: self)
        
        let deltaX = touchLoc.x - prevTouchLoc.x
        player.position.x += deltaX
        
        player.xScale = deltaX < 0 ? 1 : -1
    }
//set x flip based on delta
if deltaX < 0 {
    player.xScale = -1
} else if deltaX > 0 {
    player.xScale = 1
}

如果 deltaX 为 0,则不要更改 xScale