[Resolved] Tap event listener help !

Hello there

I am trying to separate main [Game] group and [Pause] group. The problem is my [Game] group have some object with the same position of the button of the [Pause] group. These buttons and objects both have tap event listener.

When I display the pause menu, how can I make only the buttons on the pause menu do the listeners and the object do nothing ? [import]uid: 111309 topic_id: 24928 reply_id: 324928[/import]

Are you using return true? [import]uid: 52491 topic_id: 24928 reply_id: 101187[/import]

I don’t get it, where do i have to put return true :frowning: [import]uid: 111309 topic_id: 24928 reply_id: 101194[/import]

Typically you would put the code “return true” at the end of your listener’s target function. This will STOP the signal (touch) going “through” the object or button to other sensitive objects below it in z-index.

However, I don’t think this applies to TAP objects. I think the signal will pass through tap objects even If you put “return true” in the target function.

What I suggest is setting a boolean flag to determine which “state” the user is currently in. If they are in the game, then you only allow game buttons to be tapped or touched. If they are in the pause state, then you don’t allow game buttons to operate (only pause buttons). Simply change the boolean state based on where the user is or isn’t, and use if-then code to allow or disallow the taps.

Brent [import]uid: 9747 topic_id: 24928 reply_id: 101213[/import]

Thank you Brent, your solution is great to my problem.

But I have other questions:

  • Is it possible to set focus of listener to work only certain groups ?
  • There are 3 image stack on each others. They all have tap listener. Can we ignore the first image 's tap listener, do and stop at the second’s image listener ? [import]uid: 111309 topic_id: 24928 reply_id: 101231[/import]

@ ZodiacLeo123,

I don’t think you can set “focus” on an entire display group, however it might be possible. I never use the “obj:setFocus()” API so I can’t say if it’s possible or not.

I need to correct my last post. You *can* use “return true” with tap listeners. If you have 3 objects on top of each other, only the first one (top) will receive the tap if you put “return true” in the object’s target listener function.

So, if you want to skip the top object, and use only the object behind it, you still need to tell Corona that the top object can’t be tapped (setting a boolean flag on each object is the cleanest method). Then, only “return true” IF an object has received a signal. That will prevent the tap from going through to the 3rd layer down.

Here’s a bare-bones example. “.active” in this case is the boolean flag applied to each object. It is only “true” for the object that you allowed to be tapped; otherwise false.

local function selectObject( event )  
  
 local obj = event.target  
  
 if ( obj.active == true ) then  
 object.active = false  
 elseif ( obj.active == false ) then   
 obj.active = true   
 return true  
 end  
end  

Hope this helps get you on the right track. :slight_smile: Without knowing your exact design and how you want to build the specific tap capabilities, this example is only a basic idea.

Brent
[import]uid: 9747 topic_id: 24928 reply_id: 101467[/import]

Thank you Brent

Now control tap listener seems like no problem to me :> [import]uid: 111309 topic_id: 24928 reply_id: 101792[/import]