Here is a simple class that you can reuse if you do it right, you can for example set a counter that counts down whenever the player is moving and create an animation from a "Sprite Strip"
public class SpriteAnimation : Microsoft.Xna.Framework.DrawableGameComponent
{
int Rows, CurrentRow, Columns, CurrentColumn, X, Y, Width, Height;
Texture2D Texture;
SpriteBatch SpriteBatch;
Rectangle destRectangle, sourceRectangle;
public SpriteAnimation(int rows, int columns, Texture2D texture, SpriteBatch spriteBatch, Game game) : base(game)
{
this.Rows = rows;
this.Columns = columns;
this.SpriteBatch = spriteBatch;
this.Texture = texture;
this.Width = this.Texture.Width / this.Columns;
this.Height = this.Texture.Height / this.Rows;
SetPosition(0, 0);
SetFrame(0, 0);
}
public void SetPosition(int x, int y)
{
X = x;
Y = y;
destRectangle = new Rectangle(X, Y, Width, Height);
}
public void SetFrame(int row, int column)
{
if (row >= 0 && row <= (Rows - 1))
{
CurrentRow = row;
}
if (column >= 0 && column <= (Columns - 1))
{
CurrentColumn = column;
}
sourceRectangle = new Rectangle((CurrentColumn * Width), (CurrentRow * Height), Width, Height);
}
public override void Update(GameTime gameTime)
{
base.Update(gameTime);
KeyboardState state = Keyboard.GetState();
if (state.IsKeyDown(Keys.Space)) { /* SetFrame(0, 1) */ }
}
public override void Draw(GameTime gameTime)
{
base.Draw(gameTime);
SpriteBatch.Begin();
SpriteBatch.Draw(Texture, destRectangle, sourceRectangle, Color.White);
SpriteBatch.End();
}
}
If you check the link above that I include "Sprite Strip", you see that they're divided into columns and rows and that's what you use them for. For your animation, create a texture that has all four states and then you can jump between them whenever you need. So if you have all the different state textures on one row, then row = 1, columns = 4. Then you can extend this class to make it handle an animation yourself.