如何在pixijs容器中应用不会在页面刷新时显示其颜色的蒙版? [英] How to apply mask in pixijs container that will not show it's color at page refresh?
问题描述
我正在使用以下代码在容器中应用遮罩,但是单击页面(chrome)上的刷新按钮后,pixi阶段将变为完全白色,直到刷新完成.你知道如何解决这个问题吗?
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;
推荐答案
掩码不应该是容器的子级.您正在创建一个精灵,将其添加为 visible 子级,然后使用该精灵的边界矩形作为遮罩.
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.
删除 addChild()
调用,它将正确屏蔽,但此外,如果您正在做的只是将容器桅杆设置为PIXI.Rectangle而不是sprite,遮盖矩形区域.
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.
这篇关于如何在pixijs容器中应用不会在页面刷新时显示其颜色的蒙版?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!