Gonzales Posted October 14, 2018 Share Posted October 14, 2018 Hello! I am having a hard time trying to mask/clip a square sprite into a round one. Whenever I create a Graphics object then assign it to the `mask` property on a Container or a Sprite, the whole browser freezes up and I can't even debug where the issue is, sometimes my OS even logs me out when my devtools window is still loading up (perhaps due to CPU or RAM overload?)... ? Any help would be super appreciated! I've been trying to figure this out for hours! My code is something like below: import * as PIXI from 'pixi.js'; const app = new PIXI.Application({ width: 600, height: 600, antialias: true, }); document.getElementById('root').appendChild(app.view); const mask = new PIXI.Graphics(); mask.beginFill(0x000000); mask.drawCircle(200, 200, 150); mask.endFill(); const container = new PIXI.Container(); container.mask = mask; // If I don't set the mask, everything works OK. app.stage.addChild(container); // Sprites have problem too // // const sprite = new PIXI.Sprite(/*some texture*/); // sprite.mask = mask; // app.stage.addChild(sprite); // // Now open up browser and wait to be logged out :( Quote Link to comment Share on other sites More sharing options...
ivan.popelyshev Posted October 14, 2018 Share Posted October 14, 2018 you should also add mask to the stage, however that's not ethe issue. Try set antialias to "off" , or maybe your device (linux drivers?) dont support webgl STENCIL mode Quote Link to comment Share on other sites More sharing options...
Gonzales Posted October 14, 2018 Author Share Posted October 14, 2018 3 minutes ago, ivan.popelyshev said: you should also add mask to the stage, however that's not ethe issue. Try set antialias to "off" , or maybe your device (linux drivers?) dont support webgl STENCIL mode Wow it really was because of the antialias setting, I never suspected that! Thank you so much! But what can I do if I do need the antialiasing? Quote Link to comment Share on other sites More sharing options...
ivan.popelyshev Posted October 14, 2018 Share Posted October 14, 2018 antialias can make Graphics edges smooth, but its slowing everything Quote Link to comment Share on other sites More sharing options...
Gonzales Posted October 14, 2018 Author Share Posted October 14, 2018 2 minutes ago, ivan.popelyshev said: antialias can make Graphics edges smooth, but its slowing everything Also I'm still getting used to understanding how Pixi works. May I ask why should I also add mask to the stage? (because I though since the mask is "attached" to the container, when the container is added to the stage, the mask gets added with container) Thank you! Quote Link to comment Share on other sites More sharing options...
ivan.popelyshev Posted October 14, 2018 Share Posted October 14, 2018 That's same behaviour as in Flash. Mask should be added in stage so you can position it inside another container, and when you move that container, mask also moves. It affects only the transform. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.