@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度之间的每个角度。这就是我所拥有的,现在找不到要做什么。有帮助吗?
答案 0 :(得分:0)
我认为UISwipeGestureRecognizer
不够灵活,无法满足您的需求。您可能需要使用UIPanGestureRecognizer
This tutorial on UIGestureRecognizer应该具有您要查找的内容,尤其是有关减速的部分。