この質問の続きです。(https://teratail.com/questions/71493)
override func touchesMoved(_ touches: Set<UITouch>, with event: UIEvent?){ for touch in touches{ _ = 0.01 let newPosition = touch.location(in: self) let oldPosition = touch.previousLocation(in: self) let xTranslation = newPosition.x - oldPosition.x if centerSelectWorldBTN!.frame.midX > size.width/2 { if (leftSelectWorldBTN != nil) { let actualTranslation = leftSelectWorldBTN!.frame.midX + xTranslation > leftGuide ? xTranslation : leftGuide - leftSelectWorldBTN!.frame.midX movePlayerByX(player: leftSelectWorldBTN!, x: actualTranslation) } } else { if (rightSelectWorldBTN != nil) { let actualTranslation = rightSelectWorldBTN!.frame.midX + xTranslation < rightGuide ? xTranslation : rightGuide - rightSelectWorldBTN!.frame.midX movePlayerByX(player: rightSelectWorldBTN!, x: actualTranslation) } } movePlayerByX(player: centerSelectWorldBTN!, x: xTranslation) } } override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?) { let duration = 0.25 switch zoneOfCenterSelectWorldBTN() { case .Left: if (rightSelectWorldBTN != nil) { movePlayerToX(player: centerSelectWorldBTN!, x: leftGuide, duration: duration) if (leftSelectWorldBTN != nil) { movePlayerToX(player: leftSelectWorldBTN!, x: leftGuide, duration: duration) } if (rightSelectWorldBTN != nil) { movePlayerToX(player: rightSelectWorldBTN!, x: size.width/2, duration: duration) } centerSelectWorldBTN = rightSelectWorldBTN setLeftAndRightSelectWorldBTN() } else { movePlayerToX(player: centerSelectWorldBTN!, x: size.width/2, duration: duration) } case .Right: if (leftSelectWorldBTN != nil) { movePlayerToX(player: centerSelectWorldBTN!, x: rightGuide, duration: duration) if (rightSelectWorldBTN != nil) { movePlayerToX(player: rightSelectWorldBTN!, x: rightGuide, duration: duration) } if (leftSelectWorldBTN != nil) { movePlayerToX(player: leftSelectWorldBTN!, x: size.width/2, duration: duration) } centerSelectWorldBTN = leftSelectWorldBTN setLeftAndRightSelectWorldBTN() } else { movePlayerToX(player: centerSelectWorldBTN!, x: size.width/2, duration: duration) } case .Center: movePlayerToX(player: centerSelectWorldBTN!, x: size.width/2, duration: duration) if (leftSelectWorldBTN != nil) { movePlayerToX(player: leftSelectWorldBTN!, x: leftGuide, duration: duration) } if (rightSelectWorldBTN != nil) { movePlayerToX(player: rightSelectWorldBTN!, x: rightGuide, duration: duration) } } calculateZIndexesForPlayers() } }
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。