Ccui.Button touches fall through? [SOLVED]

Hi,

I have multiple overlapping ccui.Layouts with ccui.Buttons in them. Now when I touch a button in the Layout on top sometimes the touch is also registered on the Button of Layout below:

Touch
|
Button in Layout 1 --> touchEventListener fires!
|
Button in Layout 2 --> touchEventListener fires!

It seems that this happens more when the buttons are very close together (similar x/y-position).

All buttons and layouts have .setSwallowTouches(true) enabled and the topmost layout has set a higher localZOrder. I would expect that the touch is swallowed by the topmost button.

What do I have to do to stop propagation of the touch? Or is this a known limitation?

I’ve not used ccui.Button, but the usual cc.EventListener requires the onTouchBegan function to return true; somewhere. Otherwise, the touch isn’t swallowed. May that be the issue?

Hi,

Thanks for your response.

The problem was that I had to setTouchEnabled(true) and setSwallowTouches(true) on the layout itself (I forgot the first one). The layout should act as a dialog window, so by enabling it for touches and swallowing them it prevents the touches from “falling through”.