Update: touchesEnded

pull/14/head
Nathan VERDIER 11 months ago
parent 19156a0be7
commit 4daa6239de

@ -58,30 +58,20 @@ class SpriteMeeple : SKNode {
}
override func touchesEnded(_ touches: Set<UITouch>, 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<UITouch>, with event: UIEvent?){
self.position = touches.first?.location(in: parent!) ?? CGPoint(x: 0, y: 0)
}

Loading…
Cancel
Save