Incorrect Sprite Aspect Ratio

I’m using SpritePackedManager and my character sprite (64x96) seems to be stretched after being rendered. How can I fix this so that it keeps it’s aspect ratio?

This is after scaling the window (what the sprite should look like but not the 3d environment)

Does anyone have any guidance on this?

Hi tonyfirgun,

It looks like two things are going on. First, it doesn’t look like your scene is hooked up to react to window resize events, which is why it squashes and stretches when you change the window size. This should be an easy fix; all you should have to do is add something like the following wherever your Babylon.Engine lives.

window.addEventListener('resize', function () {
    engine.resize();
});

The second thing going on is that it looks like your sprite thinks it’s a square instead of a rectangle. I think this should be resolvable just by telling the sprite how big it’s supposed to be, as shown in this Playground.

sprite.width = 1;
sprite.height = 1.5;

Hope this helps, and best of luck!

3 Likes

@syntheticmagus you are on fire !!! thanks a lot

Thank you! That helped completely.