Appearance
MonoGame exporter
Output
Packrat writes a generated C# loader and one image per atlas page:
text
atlas.cs
atlas.pngThe generated class contains atlas page loading, named and indexed frame lookup, texture access, and a SpriteBatch draw helper.
Integrate
Add the .cs file to the game project. Add each generated image to the MonoGame Content project using the asset names referenced by the generated Content.Load<Texture2D> calls. Then load and draw it:
csharp
var atlas = PackratAtlas.Load(Content);
atlas.Draw(spriteBatch, "player_0001", position);Use Get, Get(name, index), or Find when an animation has repeated frame names. The helper accounts for trim offsets.
Minimal game
Assume the export base name is atlas, atlas.cs is compiled into the game, and the generated image is added to the Content project. That base name produces the PackratAtlas class below. Replace player_0001 with a frame name that exists in your atlas:
csharp
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
public sealed class DemoGame : Game
{
private readonly GraphicsDeviceManager graphics;
private SpriteBatch batch = null!;
private PackratAtlas atlas = null!;
public DemoGame() { graphics = new GraphicsDeviceManager(this); }
protected override void LoadContent()
{
batch = new SpriteBatch(GraphicsDevice);
atlas = PackratAtlas.Load(Content);
}
protected override void Draw(GameTime gameTime)
{
GraphicsDevice.Clear(Color.CornflowerBlue);
batch.Begin();
atlas.Draw(batch, "player_0001", new Vector2(400, 300));
batch.End();
base.Draw(gameTime);
}
}
public static class Program
{
public static void Main() { using var game = new DemoGame(); game.Run(); }
}