Tapping with overlapping objects: return true doesn't work

Dear all,

I’ve read a previous topic on the forum about this topic, but it seems that I can’t make it work.

All I have is a menubar that overlaps with a grid of items. When I tap an item in the bar, it seems that the tapping actually happens in the underlying items, not what I intended.

To clarify the code, the last button is the one that should work, sliding the bar open and closing it. On the iPad it works, since there is enough space and I have no overlapping objects. On my GalaxyTab 10 it doesn’t: the menu bar does not slide back.

Can anyone help me? I already added a “return true” to the event handler, as suggested in the forum.

Thanks & Cheers!

-- Add event listener for each menu menuImage:addEventListener("tap", function(event) -- The last button is only scroll if (i == #items) then if (grp.x == 0) then transition.to(grp, { time = 200, x = w - grp.width }) else transition.to(grp, { time = 200, x = 0 }) end else -- Remove everything from group before moving to the scene while (grp.numChildren \>= 1) do grp:remove(1) end director:changeScene(items[i].scene, "crossfade") return true end end ) [import]uid: 94362 topic_id: 34786 reply_id: 334786[/import]

Two rules:

  1. Tap blocking does not affect touches and vice versa. So return true in your code will only affect other “tap” listeners

  2. return true[/code] needs to be at the very end of your listener. In the way you wrote your code, it's only returning true [code]if i ~= #items[/code], so when [code]i == #items

Thanks Richard! That did the trick. The only tap I wanted to handle was the “slide back”, but I was obviously wrong.

It works perfectly with return true at the end of the listener.
Thanks! [import]uid: 94362 topic_id: 34786 reply_id: 138297[/import]

Two rules:

  1. Tap blocking does not affect touches and vice versa. So return true in your code will only affect other “tap” listeners

  2. return true[/code] needs to be at the very end of your listener. In the way you wrote your code, it's only returning true [code]if i ~= #items[/code], so when [code]i == #items

Thanks Richard! That did the trick. The only tap I wanted to handle was the “slide back”, but I was obviously wrong.

It works perfectly with return true at the end of the listener.
Thanks! [import]uid: 94362 topic_id: 34786 reply_id: 138297[/import]