我当前在SKSpriteNodes
这两个按钮上使用触摸方法。我接收到手势状态失败,但是我不确定为什么,因为我没有使用手势,所以我将touchBegan
和touchEnded
用于触摸控件。
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
for touch: AnyObject in touches {
let pointTouched = touch.location(in: self)
if leftArrow.contains(pointTouched) {
moveWizard(moveBy: -60, forTheKey: "left")
wizardRunAnimation(forTheKey: "wizardRun")
wizardNode.xScale = -1
}
if rightArrow.contains(pointTouched) {
moveWizard(moveBy: 60, forTheKey: "right")
wizardRunAnimation(forTheKey: "wizardRun")
wizardNode.xScale = 1
}
if attackButton.contains(pointTouched) {
wizardAttackAnimation()
}
}
}
override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?) {
wizardNode.removeAction(forKey: "left")
wizardNode.removeAction(forKey: "right")
wizardNode.removeAction(forKey: "wizardRun")
}