when I tried to use the method 'setOnTapListener'which belonged to the Node , I used the class named 'GestureDetector' in the callback of this method ,then I received nothing from the class of its method named 'onDoubleTap'.
So I want to know what to do next to listen for double-click events on the node.
`val curGestureDetector = GestureDetector(this@MainActivity, object : GestureDetector.SimpleOnGestureListener() {
override fun onDoubleTap(e: MotionEvent?): Boolean {
//It's not executed here
Log.i(TAG, "鐗╀綋鍙屽嚮")
transformableNode.parent.removeChild(transformableNode)
return true
}
})
transformableNode.setOnTapListener { hitTestResult, motionEvent_ ->
//Here it executed
Log.i(TAG, "鐗╀綋tap")
curGestureDetector.onTouchEvent(motionEvent_)
}`
The Tap listener is only for receiving events when a tap gesture has occurred (down and then up within a slop threshold) and is similar to View.OnClickListener in Android. To use the GestureDetector, you need to pass all touch events into the gesture detector, not just the tap. You can do this by making a subclass of Node or TransformableNode and overriding Node.onTouchEvent
@dsternfeld7 Thanks very much, you have helped me a lot .the problem has been solved
Most helpful comment
The Tap listener is only for receiving events when a tap gesture has occurred (down and then up within a slop threshold) and is similar to View.OnClickListener in Android. To use the GestureDetector, you need to pass all touch events into the gesture detector, not just the tap. You can do this by making a subclass of Node or TransformableNode and overriding Node.onTouchEvent