diff --git a/DouShouQi_App/DouShouQi_App/Components/Scene/SpriteMeeple.swift b/DouShouQi_App/DouShouQi_App/Components/Scene/SpriteMeeple.swift index 23463f6..aeaaaa3 100644 --- a/DouShouQi_App/DouShouQi_App/Components/Scene/SpriteMeeple.swift +++ b/DouShouQi_App/DouShouQi_App/Components/Scene/SpriteMeeple.swift @@ -58,29 +58,19 @@ class SpriteMeeple : SKNode { } override func touchesEnded(_ touches: Set, with event: UIEvent?) { - var x: CGFloat = 0 - var y: CGFloat = 0 - let position = touches.first?.location(in: parent!) ?? CGPoint(x: 0, y: 0) - if (position.x < -400){ - x = -400 - } - else if (position.x > 500){ - x = 500 - } - else{ - x = (abs(x.truncatingRemainder(dividingBy: 100)) < 50) ? floor(position.x/100) * 100 : ceil(position.x/100) * 100 - } - if (position.y < -300){ - y = -300 - } - else if (position.y > 400){ - y = 400 - } - else{ - y = (abs(y.truncatingRemainder(dividingBy: 100)) < 50) ? floor(position.y/100) * 100 : ceil(position.y/100) * 100 + if let parent = parent, let position = touches.first?.location(in: parent) { + // Arrondir à la case la plus proche pour x et y + let x = round(position.x / 100) * 100 + let y = round(position.y / 100) * 100 + + // Assurer que les coordonnées sont dans les limites + let clampedX = min(max(x, -300), 300) + let clampedY = min(max(y, -400), 400) + + self.position = CGPoint(x: clampedX, y: clampedY) } - self.position = CGPoint(x: x, y: y) } + override func touchesMoved(_ touches: Set, with event: UIEvent?){ self.position = touches.first?.location(in: parent!) ?? CGPoint(x: 0, y: 0)