私は既に自分のプレイヤーの動きを検出するためにジェスチャーリコナイザーをゲームに実装していますが、私には自分が望む結果を与えていないことがわかっているので、スワイプジェスチャーtouchesメソッドとタップメソッドでも同様です。私はタッチメソッドでタップ機能を動作させることに成功しましたが、タッチメソッドでスワイプ機能を実装することができず、これを行う方法に関するチュートリアルを見つけることができません。どのように私はタッチ方式は、特定の方向にスワイプジェスチャを認識させることができスワイプでのスワイプジェスチャー
class GameScene: SKScene {
var touchOrigin = CGPoint()
var player = SKSpriteNode()
override func didMove(to view: SKView) {
backgroundColor = .black
player = SKSpriteNode(texture: nil, color: .orange, size: CGSize(width: 50, height: 50))
player.position = CGPoint(x: 0, y: 0)
addChild(player)
}
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
}
override func touchesMoved(_ touches: Set<UITouch>, with event: UIEvent?) {
}
override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?) {
for touch in touches {
var currentTouchPosition = touch.location(in: self)
touchOrigin = touch.location(in: self)
if (Int(touchOrigin.x) > Int(currentTouchPosition.x)) {
player.position.x -= 50
} else if (Int(touchOrigin.x) < Int(currentTouchPosition.x)) {
player.position.x += 50
}
if touch.tapCount == 1 {
player.position.y += 50 //replace this with function :)
} else if touch.tapCount >= 2 {
player.position.y += 150 // change to run shield effect :)
}
}
}
override func touchesCancelled(_ touches: Set<UITouch>, with event: UIEvent?) {
}
}
:以下の私のコードは、私はこれを試してみて、達成するために使用していますタッチ方法を示して?それらがある方向にスワイプして画面から指を離して1つのモーションで原点にスワイプすると、どのようにしてそれをタップとして認識できるのですか?