How can I avoid sprite distortion as the frame's bounding box changes?

614 views Asked by At

I have a spritesheet (packed by the wonderful TexturePacker) that looks like so:

enter image description here

and the animation as an animation works well using the current code. However, when the animation moves to a frame where the bounding box is smaller (e.g. when the legs are closer, when the figure is kneeling, etc.), the image distorts so that the smaller bounding box fills the bounding box of the sprite.

How can I fix this?

The spritesheet above is a frame-extraction from a sample Adobe flash animation.

2

There are 2 answers

0
Kumar Saurabh On

cant give you a link but here is what i do for these situations

  1. while making the texture packer strip the white space
  2. make a array of AtlasSprite for images
  3. then in my render method

    public void render(float delta) {
         atlasSprite = animation.getKeyFrame(statetime, Animation.LOOPING);
         atlasSprite.draw(batcher)
    };
    
  4. in my update method, which gives exact rectangular bounds of the current image displayed. Since you have stripped the whitespace and used AtlasSprite so bounds will be without blank whitespace.

    public void update(float delta) {
        bounds = sprite.getBoundingRectangle();
    }
    

P.S. this is just a pseudo code and many syntatical error could be there its just to give you a idea

1
Daahrien On

Easier way: You can make all the textureregions the same size.

Hard way: Keep it like this, but you need to save and calculate the size and position of every textureregion to draw.

I personally recommend you the first option, just make all the image the same size.