2

I use this touch.tapCount in touchesBegan and try to print the value but it never return 2.

Any idea why? It can be 1,3,,5,7,9, .... but not 2,4,6,8,10, ...

override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {


    if let touch = touches.first {
        //print(touch.tapCount)
        if ((touch.tapCount) == 1) {
            player.animatedPlayer()
            jump = true
        }
    }

}
vhao91
  • 23
  • 4

1 Answers1

0

You should use UITapGestureRecognizer to handle tapEvent. the numberOfTapsRequired property make this detect DoubleTap only

 override func viewDidLoad() {
     super.viewDidLoad()
     var tap = UITapGestureRecognizer(target: self, action: 
     #selector(self.handleTapGesture(gesture:)))
     tap.numberOfTapsRequired = 2
     self.scene?.view?.addGestureRecognizer(tap)
 }

 @objc func handleTapGesture(gesture: UITapGestureRecognizer) -> Void {
    // do something here
 }

Hope helpfull!

Tritmm
  • 1,972
  • 18
  • 14