"touch" event listener detected by multiple objects?

I just put a “pause” button in on my game and the object listener beneath it apparently also detects touches when I click on it (so both the pause button and the rectangle object listener beneath the button receive touch events). I was expecting that only the object furthest to the “front” would detect a touch. Was I correct in thinking this? Apparently not since it doesn’t seem to function this way.

What’s the best way to keep my “touch” event contained to the topmost display object (just the “pause” button)?

Thanks! [import]uid: 105707 topic_id: 34689 reply_id: 334689[/import]

at the end of pause function add

return true  

return true lets the app know that you are done with that touch and to not do anything at all after “return true” .

Beware though, tap and touch listeners work separately, return true won’t help if you’re using both if I remember right [import]uid: 77199 topic_id: 34689 reply_id: 137827[/import]

I had similar issues check out:
http://developer.coronalabs.com/forum/2012/11/10/learning-events-setfocus-or-detecting-touchtap-events-object-not-working#comment-130763 [import]uid: 179798 topic_id: 34689 reply_id: 137980[/import]

Hi Guys,

Thanks for the tips, problem solved :slight_smile:

I am currently only using “touch” events but it’s interesting to see how to manage “touch” and “tap” in the same circumstance. The solution makes sense, thanks for the link.

[import]uid: 105707 topic_id: 34689 reply_id: 138018[/import]

at the end of pause function add

return true  

return true lets the app know that you are done with that touch and to not do anything at all after “return true” .

Beware though, tap and touch listeners work separately, return true won’t help if you’re using both if I remember right [import]uid: 77199 topic_id: 34689 reply_id: 137827[/import]

I had similar issues check out:
http://developer.coronalabs.com/forum/2012/11/10/learning-events-setfocus-or-detecting-touchtap-events-object-not-working#comment-130763 [import]uid: 179798 topic_id: 34689 reply_id: 137980[/import]

Hi Guys,

Thanks for the tips, problem solved :slight_smile:

I am currently only using “touch” events but it’s interesting to see how to manage “touch” and “tap” in the same circumstance. The solution makes sense, thanks for the link.

[import]uid: 105707 topic_id: 34689 reply_id: 138018[/import]

I have a weird case that seems to break the simple “return true” solution to this issue. I’ve added my pauseButton object to a storyboard group (“group:insert(pauseButton)”) and now I get the touch propogating through as before.

Any idea why this breaks the “return true” solution?

[import]uid: 105707 topic_id: 34689 reply_id: 138955[/import]

I have a weird case that seems to break the simple “return true” solution to this issue. I’ve added my pauseButton object to a storyboard group (“group:insert(pauseButton)”) and now I get the touch propogating through as before.

Any idea why this breaks the “return true” solution?

[import]uid: 105707 topic_id: 34689 reply_id: 138955[/import]

Could you provide a bit of code? Most likely the issue is that the objects are getting added above the pauseButton, but without seeing the sequence it would be difficult to comment. [import]uid: 135394 topic_id: 34689 reply_id: 142097[/import]

Could you provide a bit of code? Most likely the issue is that the objects are getting added above the pauseButton, but without seeing the sequence it would be difficult to comment. [import]uid: 135394 topic_id: 34689 reply_id: 142097[/import]