New issue 163 by mikejohnwyatt: Event order
What steps will reproduce the problem?
1. Create a heirarchy of event-handling layers. At least one of the layers
should have multiple child layers. All layers should handle the same event
and not return EVENT_HANDLED.
2. Run the program and fire the event.
What is the expected output?
I expect the event handlers to be called in the following order:
What do you see instead?
In reality, the order is like this:
The problem is that the event handlers are simply pushed onto the window in
order of the layer's children list (which is sorted with the lowest Z
values first). This results in the handlers being called from
back-to-front, instead of the documented front-to-back (from
\cocos\layer\base_layers.py: "Events are propagated to layers (from front
to back) until some layer catches the event and accepts it.").
I need the order to be front-to-back so I can implement a basic GUI, in
which events (like a mouse click) can be first caught by a widget (like a
button) before being optionally passed to the background (i.e. if no button
I have attached a patch file to fix this issue. Basically I just reversed
the order of pushing child handlers onto the window in the scene and
layer's push_all_handlers() method. I also removed event pushing from the
on_enter method, since that would otherwise cause events to be registered
in order of on_enter being called.
event order fix.patch 2.4 KB