How to apply mask in pixijs container that will not show it's color at page refresh?

旧巷老猫 提交于 2021-01-29 18:01:48

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!