Closed gsotirov closed 3 years ago
you should add mask to stage too, there are no guarantees for stage-less masks.
It should work, need complete example
Thanks for the swift response, Ivan. Yes, when I added it directly to the stage it worked, But if the display object used as a mask is added to a Container that is rendered on a specific layer, the above-mentioned problem happened. That was the case with my initial implementation.
const stage = new display.Stage();
const group = new Group(0, true);
const layer = new Layer(group);
stage.addChild(layer);
const container = new Container(); // The container has some children inside, 1 of which will be used as a mask.
container.parentGroup = group;
layer.mask = container.children[0];
Oh, now i know whats wrong and i think i can reproduce it. thank you!
You are welcome. @ivanpopelyshev Since I guess it could take a while before the eventual fix is added, can you share where the issue is so I can try a temp solution from my end ?
most possibly something with if (this._activeParentLayer)
. It should be ignored if element is a mask
@gsotirov actually, if your layer has only dynamic objects - they wont affect bounds, and bounds are required for sprite masks. You may add filterArea to that layer, like layer.filterArea = renderer.screen
, or override calculateBounds
or add a graphics with a rect that has alpha=0.
Please confirm that was the issue!
Here's important notice for you: https://github.com/pixijs/layers#important-notice-about-filters-and-masks
Nope, I failed to reproduce your case. Can you please put it on jsfiddle or pixi-playground or codesandbox?
Thanks @ivanpopelyshev, for the notice.
Sorry for the late response, I've been busy. While making the example, I was able to make it work, but only if the mask is rendered on the same layer I wanted to mask with it. If I want to use the mask to mask two layers, it won't work.
Here's what I did: https://codesandbox.io/s/pixi-playground-forked-8lwo1?file=/src/index.js
Comment/Uncomment lines 49 & 50 to reproduce.
When setting
layer.mask = <some_mask>
all display objects on the layer disappear. Can layers be masked ?Example code: