Sia Posted January 24, 2021 Share Posted January 24, 2021 Hi everyone I have a texture which I use it in Graphics.lineTextureStyle : the whole code goes like this : const app = new PIXI.Application({ antialias: true , width:1000 , height:1000 , backgroundColor: 0xFFFFFF }); document.body.appendChild(app.view); const texture = PIXI.Texture.from('./a.png'); // the size of image file : 900*900 const g = new PIXI.Graphics(); g.lineTextureStyle({width:40 , texture:texture , alignment:0}); g.beginFill(0); g.drawRect(0,0 , 900,900); // the size of rectangle : 900*900 g.endFill(); app.stage.addChild(g); the result : now I want to change the size of rectangle to 400*400 but texture stays the same size so most of texture gets clipped like so : how to change the size of texture to match it with the size of rectangle ? Quote Link to comment Share on other sites More sharing options...
ivan.popelyshev Posted January 24, 2021 Share Posted January 24, 2021 pass the matrix in method , with a scale Sia 1 Quote Link to comment Share on other sites More sharing options...
Sia Posted January 24, 2021 Author Share Posted January 24, 2021 could you please be more specific ? Quote Link to comment Share on other sites More sharing options...
ZackMercury Posted January 24, 2021 Share Posted January 24, 2021 (edited) I think he meant this: g.lineTextureStyle({width:40 , texture:texture , alignment:0, matrix: PIXI.Matrix.IDENTITY.scale(the scale you need)}); And you can calculate the scale like this: scaleX = rectWidth / TEXTURE_SIZE scaleY = rectHeight / TEXTURE_SIZE Edited January 24, 2021 by ZackMercury Sia 1 Quote Link to comment Share on other sites More sharing options...
ivan.popelyshev Posted January 24, 2021 Share Posted January 24, 2021 please dont change IDENTITY matrix, clone it at least first! Quote Link to comment Share on other sites More sharing options...
ZackMercury Posted January 24, 2021 Share Posted January 24, 2021 (edited) Wait, what? PIXI Matrix is not immutable? Ah, my bad. g.lineTextureStyle({width:40 , texture:texture , alignment:0, matrix: PIXI.Matrix.IDENTITY.clone().scale(the scale you need)}); Edited January 24, 2021 by ZackMercury Sia 1 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.