A sprite sheet (also known as a texture atlas) is a single image file that contains multiple smaller graphics (sprites) arranged in a grid. Instead of loading 50 different images for a character's walk cycle, attack animation, and idle states, you load one large image and define rectangles to specific parts of it.

Here's an example of how to use a sprite sheet to create an animated sprite:

While coding the rendering logic is important, creating the sprite sheet itself is often the bottleneck for artists and solo devs.

public AnimatedSprite(Texture2D spriteSheet, Rectangle[] spriteFrames, float frameRate)

spriteBatch.Draw(spriteSheet, position, spriteFrames[currentFrame]);

spriteBatch.Draw(playerSheet, playerPosition, sourceRect, Color.White);

The magic of sprite sheets lies in the Source Rectangle . This tells the SpriteBatch.Draw method exactly which portion of the large image to display.

Pete felt his consciousness leap from the first cell of the first row to the first cell of the second. He was no longer idling; he was walking. “Here we go again,” he thought, as the animation timer cycled him through frames five, six, seven, and eight. His legs pumped in perfect sync with the delta time. He felt the friction of the floor—a series of tiled grass textures—beneath his boots. For a few glorious seconds, he wasn't a grid of pixels; he was a hero on a quest. But then, a logic error occurred. The developer had forgotten to reset the animation frame counter when Pete hit a wall.

public Animation(Texture2D texture, int frameWidth, int frameHeight, float frameDuration, bool isLooping)

public void Draw(SpriteBatch spriteBatch, Vector2 position)

this.spriteSheet = spriteSheet; this.spriteFrames = spriteFrames; this.frameRate = frameRate; this.currentFrame = 0;

Texture2D spriteSheet; spriteSheet = Content.Load<Texture2D>("spriteSheet");