How to touch and hold a node in Swift?

I am currently working on a project where I need the user to click on a node in order to do an action. So I am currently working with some code that will allow this to happen, but only if the user touches the screen.

I want it to work when the user touches a specific node. Any help is appreciated! My code is in the picture below.

Thank! Code

+3


source to share


1 answer


Since you already know how to make the gesture, the rest is easy:

All we are going to do is take a point from the view, convert it to scene coordinates, and grab 1 / all node from the scene.



@IBAction func TELE(_ gestureRecognizer : UILongPressGestureRecognizer) {

    if gestureRecognizer.state == .began{
         var touchPoint = gestureRecognizer.location(in: view)
         var touchPointInScene = view.scene.convertPoint(fromView:touchPoint)

         //use atPoint for the deepest node, node(:at) for all nodes)
         var node = view.scene.atPoint(touchPointInScene)
         var nodes = view.scene.nodes(at:touchPointInScene)

    }
}

      

+3


source







All Articles