noone 0 Report post Posted November 29, 2020 (edited) I'm creating a sprite with random width and height but when I load the texture it stretch and not keeping the aspect ratio, see it here. How can i fill a sprite with the texture but keep the aspect ratio? Edited November 29, 2020 by noone Quote Share this post Link to post Share on other sites
ivan.popelyshev 1079 Report post Posted November 29, 2020 pixijs doesnt have any resizing options to preserve aspect ratio. Usual stuff, after you load texture, just take "min(scale.x, scale.y)" and assign it to object scale. Quote Share this post Link to post Share on other sites
noone 0 Report post Posted November 29, 2020 8 minutes ago, ivan.popelyshev said: pixijs doesnt have any resizing options to preserve aspect ratio. Usual stuff, after you load texture, just take "min(scale.x, scale.y)" and assign it to object scale. Thanks for the reply ivan. Do you mind writing a code snippet on how do i got about it? Quote Share this post Link to post Share on other sites
ivan.popelyshev 1079 Report post Posted November 29, 2020 No, because I think that you'll have problems even if I do bigger snippet. Those are the basics of pixi transforms. or flash transforms. or other 2d renderers. Make a minimal demo on jsfiddle, pixi-playground or codepen - i edit it and fix it if you do it wrong ) Quote Share this post Link to post Share on other sites
noone 0 Report post Posted November 29, 2020 (edited) Here you go:https://codepen.io/quickfingers/pen/QWKwVEq As you refresh you'll see it get stretch. Edited November 29, 2020 by noone Quote Share this post Link to post Share on other sites
ivan.popelyshev 1079 Report post Posted November 29, 2020 (edited) Here you go: https://codepen.io/ivanpopelyshev/pen/NWRPLOy in 4.4.5 you had to do something like that use use pixi loader. in v5 you can do the following to wait for it to load: https://www.pixiplayground.com/#/edit/9z1BH9bfLlwwX4DGcn_N0 Edited November 29, 2020 by ivan.popelyshev Quote Share this post Link to post Share on other sites
noone 0 Report post Posted November 29, 2020 thank you! this is very helpful is there a way to scale the texture to fill the sprite with the texture but keep the aspect ratio? Quote Share this post Link to post Share on other sites
ivan.popelyshev 1079 Report post Posted November 29, 2020 (edited) well, you have to cut it, you can use "new PIXI.Texture(oldTexture, new PIXI.Rectangle(x,y,w,h))" where x,y,w,h are obtained through mathematics based on scale stuff ) and scale the sprite anyway Edited November 29, 2020 by ivan.popelyshev Quote Share this post Link to post Share on other sites