andreas_d Posted July 29, 2015 Share Posted July 29, 2015 Hi guys,// image is 500x500var bg = new PIXI.Sprite.fromImage(image) container.addChild(bg);// mask is 200x200bg.mask = container.addChild(new PIXI.Graphics().beginFill().drawRect(0,0,200,200).endFill()) container.width // is 500container.height // is 500Is there a built in way to get the width and height of container taking the mask into account? Does anyone know of a good practice in this situation? Quote Link to comment Share on other sites More sharing options...
xerver Posted July 29, 2015 Share Posted July 29, 2015 The mask isn't technically drawn in the container, since it is a mask; so it isn't included in the size. I would avoid adding masks to the scene as they will not do what you expect. Also, the mask doesn't change the object's size it just hides some pixels. The size we report is still based on the object, not the finally drawn image. Quote Link to comment Share on other sites More sharing options...
andreas_d Posted July 29, 2015 Author Share Posted July 29, 2015 Hi xerver ... again I've had weird results with that actually. Taking the above example, if I don't add the mask as a child, it doesn't scale if the parent container has it's dimensions changed. for example: // image is 500x500var bg = new PIXI.Sprite.fromImage(image) container.addChild(bg);// mask is 200x200var mask = new PIXI.Graphics().beginFill().drawRect(0,0,200,200).endFill()) // after scaling mask is 100x100//bg.mask = container.addChild(mask)// after scaling mask remains 200x200 bg.mask = mask container.scale = new PIXI.Point(0.5, 0.5);Also on a another note using container.width=200 in the above example causes an error in which the image gets distorted (width doesn't change and image becomes ver stretched on the x axis) Thanks for your help ... once again Andreas Quote Link to comment Share on other sites More sharing options...
xerver Posted July 29, 2015 Share Posted July 29, 2015 Taking the above example, if I don't add the mask as a child, it doesn't scale if the parent container has it's dimensions changed. Yeah that is true we actually have an open bug for it: https://github.com/pixijs/pixi.js/issues/1978 Also on a another note using container.width=200 in the above example causes an error in which the image gets distorted (width doesn't change and image becomes ver stretched on the x axis) Setting the width/height of an object directly modifies the scale of the object to force it to those dimensions. 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.