Respond to tap in no widget

In my app I have a few buttons in the corners, and a large “background” space that takes up the rest of the screen. I want to write a handler that responds to a tap ONLY IF IT IS NOT IN ANY WIDGET.

       display.currentStage:addEventListener(“tap”, nextTurn)

creates a handler that responds to every tap,  even if it was in a widget. How can I get the distinction I need?

There are two types of events that get generated with taps:   a tap event if the touch starts and ends in a certain time window and there isn’t much in the way of moment and a set of touch events (the began phase, ended phase and possible moved phases).  

Depending on the widget (I’m going to assume widget.newButton), it’s only handling a touch event and letting the tap event go through.  

I would suggest having your background handle touch events and not taps.

Rob

Thanks, Rob, appreciate the quick response. But it doesn’t seem to solve the problem. My background:

      display.currentStage:addEventListener(“touch”, nextTurn)

 is still getting touch/began events right through the buttons. Any more good ideas?

Thanks,

Ken

I never use currentStage.  It’s the highest order display object and it may be acting like the front most element, not the back most.  Do you have a background object (image, rectangle) that you could but it on instead of currentStage?

Rob

Returning from holiday and other distractions, I have tried your suggestion.  It STILL lets events through to the background object behind the buttons. My background object is colored, so it plainly shows that it is correctly positioned behind the buttons. Still, it gets every tap, on a button or elsewhere. Here’s the setup:

  bg = display.newRect(0, 0, screen.width, screen.height)

  – then I color it –

  bg:addEventListener(“touch”, nextTurn)

Hi @k3_sparklight,

I think this tutorial should clarify some of this, and give you the workaround you need:

http://www.coronalabs.com/blog/2013/10/01/tutorial-taptouch-anatomy/

Sincerely,

Brent Sorrentino

Thanks, Brent, it was the “return true” that I didn’t understand, that was all. Problem solved.

There are two types of events that get generated with taps:   a tap event if the touch starts and ends in a certain time window and there isn’t much in the way of moment and a set of touch events (the began phase, ended phase and possible moved phases).  

Depending on the widget (I’m going to assume widget.newButton), it’s only handling a touch event and letting the tap event go through.  

I would suggest having your background handle touch events and not taps.

Rob

Thanks, Rob, appreciate the quick response. But it doesn’t seem to solve the problem. My background:

      display.currentStage:addEventListener(“touch”, nextTurn)

 is still getting touch/began events right through the buttons. Any more good ideas?

Thanks,

Ken

I never use currentStage.  It’s the highest order display object and it may be acting like the front most element, not the back most.  Do you have a background object (image, rectangle) that you could but it on instead of currentStage?

Rob

Returning from holiday and other distractions, I have tried your suggestion.  It STILL lets events through to the background object behind the buttons. My background object is colored, so it plainly shows that it is correctly positioned behind the buttons. Still, it gets every tap, on a button or elsewhere. Here’s the setup:

  bg = display.newRect(0, 0, screen.width, screen.height)

  – then I color it –

  bg:addEventListener(“touch”, nextTurn)

Hi @k3_sparklight,

I think this tutorial should clarify some of this, and give you the workaround you need:

http://www.coronalabs.com/blog/2013/10/01/tutorial-taptouch-anatomy/

Sincerely,

Brent Sorrentino

Thanks, Brent, it was the “return true” that I didn’t understand, that was all. Problem solved.