I've been struggling with this for hours now and have read posts, docs and libgdx sources to better understand what's happening, but I still can't make any sense of this.
I want to accomplish something very simple: stopping a tap on an Actor from propagating through the stage.
The setup is as follows:
GameStagedefines a gesture listener (for map panning and propagating taps in the map to thePlayeractor so it can move around)Playerhas a child actor which can receive clicks
It is on that last child actor that I want to detect clicks, but then not have them propagate to any other actors or be handled by the stage. I define the click handler as follows:
// in child actor: addListener(new ClickListener() { void clicked(...) }); Nothing surprising here.
The problem is: since the actor is physically located outside the Player parent actor, any clicks on it get picked up by the stage's map gesture handler which then propagates these taps back to the player which makes it move around. I don't want that; this click listener is supposed to handle and swallow the event.
However, none of the following calls I make inside clicked actually cancel the event:
event.handle() event.stop() event.cancel() The only way I could make the event stop from propagating is to use Stage#cancelTouchFocus. However, this has the side effect of dispatching a touchUp event on the stage (why?), which ends up in my gesture listener and gets interpreted as a longPress! Probably because it is paired up with the wrong touchDown...
What am I missing? It can't be that complicated to stop an event from propagating given all the supposed options?
UPDATE: I believe the problem lies in Stage: https://github.com/libgdx/libgdx/blob/2bd1557bc293cb8c2348374771aad832befbe26f/gdx/src/com/badlogic/gdx/scenes/scene2d/Stage.java#L348
It walks over all the listeners that have touch focus, and let's them handle the event. However, it does not break out of the loop as soon as a listener has handled it, thus propagating it further. Is that just a bug?
isHandledin every gesture callback I get, I can prevent additional logic from firing. That sounds wrong to me though, why wouldn't the event system check that for you? \$\endgroup\$