Problem understanding animating sprites with different size

Hi I posted a question in gamedevstack regarding animation. I have a spritesheet with animations in it.

For some reason my sprite is shifting position when drawing it without changing origin.

But when I change the origin to be the width and height of my sprite the sprite animates the way I want to.

Please check my question. I’ve been stuck on this problem for 2 days.

My question

that kinda looks like its scaling to me. in which case it’d be normal behavior.

characters are normally anchored like this anyway, with the y origin set to be the bottom of the sprite, and the x origin to be width / 2

You have two options:

  • You could resize the canvas of the images so that all frames become even in width and height
  • You could change the drawing position of the inbalanced frames

For the second solution imagine the following:

You have a max frame width & height of 110 but you have one frame in your animation which has a width & height of 100, then you need to place this frame on new Vector2(5, 5) to be exactly centered in the middle of the max frame dimensions (up left origin).

You need to check if that makes sense in your animation / if it looks good enough. If not you should try option 1 instead.

You have a bug that is altering your destination height unexpectedly prior to drawing to the screen.

If you look at your own picture you will see that the destination Height is changing as the square changes.
It’s changing from 118 to 122 then back to 118.
Every time the displayed destination rectangle Height value changes… the black square moves.

You can confirm that by just temporarily setting the destination height in the spriteBatch draw to some hard coded constant value.

eg
var testDest = destination;
testDest.Height = 122;
spriteBatch.Draw(texture ,testDest, source, color);