pixijs / layers

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

Can't apply mask to Container who has children with parentGroup #21

Closed SvDen closed 6 years ago

SvDen commented 6 years ago

I've just migrated from pixi-display to pixi-layers and my masks become broken. Previously all I need to do is just applying Rectangle mask to Container with multiple children and all worked fine regardless of their displayGroups.

https://jsfiddle.net/SvDenys/2om9fn3s/

Now I can't understand how to do this. I made a fiddle from the bunny example. The most important here is this line: bunniesOdd.mask = mask

Interactivity works fine, but displaying are not. Could you please help me?

ivanpopelyshev commented 6 years ago

pixijs.io is not responding, cant check this thing now. can you host https://raw.githubusercontent.com/pixijs/pixi-display/layers/bin/pixi-layers.js somewhere else ?)

ivanpopelyshev commented 6 years ago

ok, so the general idea is that bunniesOdd does not have ANY children that are renderable, they all are rendered in layers. By assigning thing.parentGroup or thing.parentLayer you have to understand that thing will be rendered inside the corresponding layer instead of its parent.

Accurately, thing will appear in layer._sortedChildren and layer will render it.

Thus, your mask is applied to nothing.

SvDen commented 6 years ago

Thank you for so fast response!

I understand it clearly, but don't understand how to fix this. Applying the mask on the each child don't looks like a best way...

ivanpopelyshev commented 6 years ago

You need things to be masked and there has to be things that are not masked between them, right?

SvDen commented 6 years ago

I need a Container that will mask all its children regardless of theirs parentGroup.

ivanpopelyshev commented 6 years ago

masks and filters are supposed to be applied to layers. Why do you need that thing and how exactly do you think to implement without the plugin?

pixi-layers can do same things that user can. so if you cant imagine how exactly masks and filters pushed and popped and how elements are ordered inside the tree, plugin wont help you.

SvDen commented 6 years ago

Why do you need that thing

I need this for sorting children between each other. Also I have a rectangle area that should not be crossed by neither of child. The only way that works is to assign mask to each children, I did it in the example with blue Bunny. I am just wondering if there is no other way,..

ivanpopelyshev commented 6 years ago

What if you assign mask to layer?

SvDen commented 6 years ago

So I need to assign mask to all layers that could be used... I just wanted some way to inherit mask area from their direct parent, not display parent. Can't realize why that worked with an old pixi-display.

ivanpopelyshev commented 6 years ago

yep.

You were lucky that it worked in pixi-display. pixi-layers were made as a branch where dev can actually decide where to put masks, exactly.

ivanpopelyshev commented 6 years ago

The point is that masks are not inherited, mask is pushed when component starts rendering and popped when it ends.

Simple "inherit" there can affect performance, seriously.

SvDen commented 6 years ago

Thank you very much for your help!