I’m not really sure about this… but once you remove the EventListener… are you still expecting the events to be passed to the object? Maybe I’m too naive here but I would say you need the Listener as long as you want events triggering your callbacks.
Each object creates its own independent listener. When two objects are at the same position I only want to receive the top object to receive the touch. So I return true in my onTouchCallback to stop the propagation of the events to the underlaying objects. This works fine. But when remove it from the scene, then returning true the propagation isn’t stopped.
I’ve fixed it in my project by delaying this to a later time, but I’ve wondered if this behaviour is expected or this is a bug.
What’s sender ?
If you remove the listener, the callback of it will not be invoked certainly.
Could you paste more codes for that? I will be glad to help you find out the problem.
Sorry to wake up this thread, but the issue still exists:
If you have a node that is touched and swallows the touch (onTouchBegan return true), but the in onTouchBegan this node also gets removed, the touch will not be swallowed.
It is not swallowed since in OnExit the event handlers registered-flag is set to false. If the registered-flag is set to false, no touches will be swallowed any longer.
I think it is wrong behaviour that a touch of a no longer existing node is not swallowed, even if you explicitely return true.
@slackmoehrle thanks for reply, what happening here is, when we click on button it creates one layer top of the button, now we have set listener as you can see in code, so when we touch layer and if we touched inbound layer it should remove from parent and that’s what happens, but now the problem is when I click on layer just above the button it’s detecting touch for layer and so it is removing layer too, but that touch is passing to button also and this touch happened in button boundary, so it creates new layer immediately but when we touch somewhere else on layer it just remove, so I guess this comment is explaining the problem
we are not sure this is the bug or not but what we think is that once layer detects touch is removed from parent and touch should not pass to button and so button click should not trigger, we are having this problem cause we have to implement Shop in-game and when player click item from the list one popup show off and that popup doesn’t cover the whole screen so we show off layer with opacity as in demo fun and so when player click on that opacity layer, current popup removed but same time below item (button) trigger and opens up new popup
one thing I notice is that you always return true; but I guess that could be appropriate for your needs. It does signal that the touch should be consumed.
I was looking at some of my games and I think we are close in how we deal with touch events