@objc func handleSwipe(gesture: UIGestureRecognizer) {
if let gesture = gesture as? UISwipeGestureRecognizer {
switch gesture.direction {
case .up:
ballPlayer.physicsBody?.applyImpulse(CGVector(dx: 0, dy: 0))
ballPlayer.physicsBody?.applyImpulse(CGVector(dx: 0, dy: 110))
print("Swiped up")
case .down:
ballPlayer.physicsBody?.applyImpulse(CGVector(dx: 0, dy: 0))
ballPlayer.physicsBody?.applyImpulse(CGVector(dx: 0, dy: -110))
print("Swiped down")
case .right:
ballPlayer.physicsBody?.applyImpulse(CGVector(dx: 0, dy: 0))
ballPlayer.physicsBody?.applyImpulse(CGVector(dx: 110, dy: 0))
print("Swiped right")
case .left:
ballPlayer.physicsBody?.applyImpulse(CGVector(dx: 0, dy: 0))
ballPlayer.physicsBody?.applyImpulse(CGVector(dx: -110, dy: 0))
print("Swiped left")
default:
print("No such gesture")
}
}
}
Я пытаюсь заставить мой узел спрайта двигаться во ВСЕХ направлениях, включая по диагонали и каждый угол между 90 и 45 градусами.Это то, что у меня есть, и я не могу понять, что делать сейчас.Любая помощь?