@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")
}
}
}
I am trying to make my sprite node move in ALL directions, including diagonally and every angle between 90 degrees and 45 degrees. This is what I have and can't find out what to do now. Any help?