From b5e73536d31d1c878a5cceaef570b5de71c00e11 Mon Sep 17 00:00:00 2001 From: Your Name Date: Thu, 30 May 2024 17:12:48 +0200 Subject: [PATCH] game mouvement finie --- .../Game/SKNodes/SpriteMoople.swift | 43 ++++++++----------- 1 file changed, 17 insertions(+), 26 deletions(-) diff --git a/ArkitDoushiQi/ArkitDoushiQi/Game/SKNodes/SpriteMoople.swift b/ArkitDoushiQi/ArkitDoushiQi/Game/SKNodes/SpriteMoople.swift index 4d94f72..b37112c 100644 --- a/ArkitDoushiQi/ArkitDoushiQi/Game/SKNodes/SpriteMoople.swift +++ b/ArkitDoushiQi/ArkitDoushiQi/Game/SKNodes/SpriteMoople.swift @@ -13,9 +13,6 @@ class SpriteMoople : SKNode { static let offset = CGPoint(x: -400, y: -300 ) static let direction = CGVector(dx: 100, dy: 100) - static let o = CGPoint(x: 100, y: 300 ) - static let l = CGVector(dx: -100, dy: -100) - let image:SKSpriteNode let ellipse:SKShapeNode = SKShapeNode(circleOfRadius: 40) @@ -38,41 +35,35 @@ class SpriteMoople : SKNode { override var isUserInteractionEnabled: Bool { - get { - return true - } - set { - // ignore - } + get { return true } + set {} } + override func touchesBegan(_ touches: Set, with event: UIEvent?) { + } override func touchesMoved(_ touches: Set, with event: UIEvent?) { - self.position = touches.first?.location(in: self) ?? CGPoint(x: 0, y: 0) + self.position = touches.first?.location(in: parent!) ?? CGPoint(x: 0, y: 0) } override func touchesEnded(_ touches: Set, with event: UIEvent?) { - self.cellPosition = findCellPosition(pos: touches.first?.location(in: self)) - } - - - func findCellPosition(pos:CGPoint?) -> CGPoint{ - if let pos = pos { - - print("o : \(SpriteMoople.o.x)") - print("l : \(SpriteMoople.l.dx)") - print("pos : \(pos.x)") + let localisation = touches.first?.location(in: parent!) + + if let localisation = localisation { - print("X : \(pos.x / SpriteMoople.o.x)") + if (localisation.x > 400 || localisation.x < -400 || localisation.y < -300 || localisation.y > 300){ + print("Hors limite !") + return + } + let posX = Int(round((localisation.x - (-400)) / 100)) + let posY = Int(round((localisation.y - (-300)) / 100)) - //print("Y : \(SpriteMoople.offset.y + SpriteMoople.direction.dy / pos.y)") - - return CGPoint(x: SpriteMoople.o.x - SpriteMoople.l.dx / pos.x, y: SpriteMoople.offset.y - SpriteMoople.direction.dy / pos.y) - } else { - return self.cellPosition + self.cellPosition = CGPoint(x: posX, y: posY) + return } } + required init?(coder aDecoder: NSCoder) { fatalError("init(coder:) has not been implemented") }