问题
I'm using the code below to apply a mask in a container, but after I click the refresh button on page (chrome) the pixi stage becomes completely white until the refresh completes. Do you know how to fix that?
let mask = new PIXI.Sprite(PIXI.Texture.WHITE);
mask.x = maskX;
mask.y = maskY;
mask.width = maskWidth;
mask.height = maskHeight;
container.addChild(mask);
container.mask = mask;
回答1:
The mask shouldn't be a child of the container. You're creating a sprite, adding it as a visible child, and then using the sprite's boundary rectangle as a mask.
Remove the addChild()
call, and it will mask properly, but in addition, you should set the container mast to a PIXI.Rectangle instead of a sprite, if all you're doing is masking a rectangular area.
来源:https://stackoverflow.com/questions/63946807/how-to-apply-mask-in-pixijs-container-that-will-not-show-its-color-at-page-refr