I have touch listener assigned to a parent node and want to find which child node is hit by the touch.
My solution works in “Preview in editor” and in “Preview in browser” but exact same code doesn’t work in real device.
Touch registration:
start ()
{
input.on(Input.EventType.TOUCH_START, this.onTouchStart, this);
}
Touch handling:
onTouchStart(event: EventTouch)
{
let location = event.getLocation()
for (let n of this.cardNodes) {
let n_tr = n.getComponent(UITransform)
let hitTest = n_tr.hitTest(location)
if (hitTest == true) {
return // HIT
}
}
}
When I’ve compared the debug positioning I found that parent and children boundingBoxes are more less the same but the touch location was doubled on real device. Has this anything to do with display scaling factor? Is it correct to use event.getLocation()? When I use uiLocation then this does not work at all.