Animating a sprite which has different sizes on the sprite sheet?

I have a spritesheet which has the animations but they are different sizes and I cannot figure out how to animate them as they keep messing up, also line keeps appearing on one of my sprites. This is what the spritesheet looks like.

I think that the line is part of the next frame. Maybe that frame has incorrect width? Also, have you tried using SamplerState.PointClamp in SpriteBatch.Begin?

And about the different sizes:
The problem here is that the size of ‘sourceRectangle’ varies, so you cannot use simple animation systems to handle animations.

One and more painful way is to make sure that your sprite sheets are consistent.

So instead of this (art from Little Fighter 2)

You would have this


Another way is to create a Animation tool to make ‘sourceRectangles’ or ‘frames’ for you. Another advantage in this is that you could change duration of each frame, add hitboxes and maybe add a flag to play sound on specific frame or something.
Then the tool exports the data in your favourite file format, for example .xml, and you load it in your game.

The animation data could look something like this in XML:

<animation name="KingIdle1" length="4" texture="king_idle1.png">
    <frame index="0" duration="6" x="0" y="0" w="55" h="43" ox="0" oy="0"> </frame>
    <frame index="1" duration="4" x="57" y="1" w="50" h="44" ox="2" oy="0"> </frame>
    <frame index="2" duration="6" x="108" y="0" w="51" h="43" ox="4" oy="3">  </frame>
    <frame index="3" duration="4" x="160" y="0" w="51" h="42" ox="1" oy="0"> </frame>
</animation>
2 Likes

How do I implement the XML?