When I'm dealing with touchesBegan, moved, etc. I am able to loop through every item at the CGPoint where the action occurred. So obviously I am dealing with everything through my GameScene.
Now when working with UITapGestureRecognizer, I can't seem to come up with the code that would tell me if there are multiple items at the point of tapping (single tap only). It's not that I want that to happen, but I fear my code may crash if it does occur.
Should UITapGestureRecognizer be handled by each SKNode that uses it? Or is there a code solution where I can handle it all through GameScene?
Here is how I deal with touches_:
And here's how I handle UITapGestureRecognizer, yet unable to figure out code to see if there's more than one SKNode:
Now when working with UITapGestureRecognizer, I can't seem to come up with the code that would tell me if there are multiple items at the point of tapping (single tap only). It's not that I want that to happen, but I fear my code may crash if it does occur.
Should UITapGestureRecognizer be handled by each SKNode that uses it? Or is there a code solution where I can handle it all through GameScene?
Here is how I deal with touches_:
Code Block override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?){ guard let touch = touches.first else { return } let location = touch.location(in: self) let touchedNodes = self.nodes(at: location) for theNode in touchedNodes{ if let node = theNode as? MyBall { .......my code,...... } } } }
And here's how I handle UITapGestureRecognizer, yet unable to figure out code to see if there's more than one SKNode:
Code Block @objc func tappedView(_ sender:UITapGestureRecognizer) { if sender.state == .ended{ let point : CGPoint = sender.location(in: self.view) var post = sender.location(in: sender.view) post = self.convertPoint(fromView: post) if let touchNode = self.atPoint(post) as? Ball{ ......my code....... } } }