【发布时间】:2018-12-03 14:58:45
【问题描述】:
@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 度之间的每个角度。这就是我所拥有的,现在不知道该怎么做。有什么帮助吗?
【问题讨论】:
标签: ios swift sprite-kit uigesturerecognizer uiswipegesturerecognizer