Registering taps off an item

I have a situation in my app where I need to popup a modal with 3 buttons (doing this using a modal scene).  I need to make the buttons clickable - not a problem usually.  And when they tap anywhere that isn’t a button - even off the modal panel, I need it to close the panel.

The problem is… I’m not sure how to capture any taps NOT on a object.  Is there a way to do that?  Should I just create a transparent PNG the full size of the screen and capture that?  Or is there a way to capture a tap/touch off an object?

Thanks!

Have you tried this?

local stage = display.getCurrentStage() -- yourTapFunction() stage:addEventListener("tap", yourTapFunction)

Hi @john.cressman,

I would create a screen-sized vector rectangle (display.newRect()) that is both invisible but also hit-testable (.isHitTestable=true). Then I would place that directly below your buttons in z-index order, and put a tap listener on it which will close the modal. Then for the buttons, just make sure that they “return true” so that any tap/touch on them does not propogate through to the vector rectangle. In this way, you’ll detect any tap/touch that does not occur on a button.

Brent

Have you tried this?

local stage = display.getCurrentStage() -- yourTapFunction() stage:addEventListener("tap", yourTapFunction)

Hi @john.cressman,

I would create a screen-sized vector rectangle (display.newRect()) that is both invisible but also hit-testable (.isHitTestable=true). Then I would place that directly below your buttons in z-index order, and put a tap listener on it which will close the modal. Then for the buttons, just make sure that they “return true” so that any tap/touch on them does not propogate through to the vector rectangle. In this way, you’ll detect any tap/touch that does not occur on a button.

Brent