Appearance
MonoGame
Packrat writes one C# class for all pages. An export named atlas produces the class PackratAtlas. Compile the generated .cs file with your game. Add each page image to the Content project using the names shown in the generated Content.Load<Texture2D> calls.
csharp
PackratAtlas atlas = PackratAtlas.Load(Content);
var run = atlas.GetAnimation("run_side");
var frame = run.Frames[0];
spriteBatch.Begin(samplerState: SamplerState.PointClamp);
atlas.Draw(spriteBatch, frame, new Vector2(400, 300), Color.White,
0f, Vector2.One * 2f, SpriteEffects.None, 0f);
spriteBatch.End();| API | Result |
|---|---|
Load(ContentManager) | Load all page textures |
Get(name) / Get(name, index) | Find a frame by key or base name; a missing key throws an exception |
GetAnimation(name) | Return animation frames in order |
GetTexture(frame) | Frame's page texture |
Draw(batch, frame/name, position, color, rotation, scale, effects, depth) | Apply trim placement and transforms |
Each frame stores Key, Name, Index, Page, SourceRectangle, OriginalSize, Offset, and Rotated. The atlas provides Frames, Animations, and PageCount. Your game controls animation timing and advances the frame index. Use SpriteEffects to mirror a frame.
The draw position is the center of the original, untrimmed frame. Rotation is measured in radians.
See Sources and outputs for frame names, trimming, and effect maps.