pixijs / layers

Separate the z-hierarchy of your scene tree from its canonical structure.
https://pixijs.io/layers/docs/
MIT License
223 stars 57 forks source link

PIXI Events propagation bug with zOrder #101

Closed edev2020 closed 1 year ago

edev2020 commented 1 year ago

When you click over an sprite with bigger zOrder but that was drawn before the one with smaller zOrder the click will go to the sprite with smaller zOrder instead.

PIXI Layers Example (Bugged): https://www.pixiplayground.com/#/edit/0ycJnTLAu3lJu4RHq3Dee PIXI Containers Example (Working fine): https://www.pixiplayground.com/#/edit/lL7_CdWFKhdzspEFjQN87

It looks like the PIXI native event system isn't respecting the PIXI Layers zOrder hierarchy.

ivanpopelyshev commented 1 year ago

I think no one actually implemented layers improvements for new events :) It worked for old ones. You can make a PR :)

edev2020 commented 1 year ago

I think no one actually implemented layers improvements for new events :) It worked for old ones. You can make a PR :)

I found a fix for now.

1) Store the objects list in a object with data like name,zOrder and anything you need to use. 2) Sort the object list by zOrder value in case the data is added dynamically and its not a static object. 3) Execute the loop to draw all the objects.

So the order objects are drawn at first is what matters for the new EventSystem to work properly with PIXI Layers.