Appearance
MonoGame.Extended exporter
How it works
Packrat writes a TexturePacker-compatible JSON descriptor and one image file for each atlas page. MonoGame.Extended's content pipeline loads the JSON as a Texture2DAtlas; the atlas then creates Sprite objects with trim offsets and original sizes already applied. Animated frame names include a zero-based index, such as run_side_0000.
API
MonoGame.Extended materializes the JSON Hash frame records as Texture2DAtlas and Sprite objects. The relevant calls and types are:
csharp
Texture2DAtlas ContentManager.Load<Texture2DAtlas>(string assetName);
Sprite Texture2DAtlas.CreateSprite(string frameName);
void SpriteBatch.Begin(
SpriteSortMode spriteSortMode = SpriteSortMode.Deferred,
BlendState blendState = null,
SamplerState samplerState = null,
DepthStencilState depthStencilState = null,
RasterizerState rasterizerState = null,
Effect effect = null,
Matrix? transformMatrix = null);
void SpriteBatch.Draw(
Sprite sprite,
Vector2 position,
float rotation,
Vector2 scale);
void SpriteBatch.End();
public bool IsVisible { get; set; }
public Color Color { get; set; }
public float Alpha { get; set; }
public float Depth { get; set; }
public SpriteEffects Effect { get; set; }frameName is the exported frame key, such as run_side_0000. The content pipeline applies the packed rectangle, trim offset, original size, and rotation. IsVisible, Color, Alpha, and Depth control the corresponding draw properties. Set sprite.Effect to SpriteEffects.FlipHorizontally or SpriteEffects.FlipVertically before drawing when needed. Dispose the atlas and SpriteBatch with the rest of the game's graphics resources.
Integrate
Add each JSON descriptor and its matching image to the MonoGame Content project. Load the descriptor asset and create a sprite by its exported frame name:
csharp
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using MonoGame.Extended.Graphics;
Texture2DAtlas atlas = Content.Load<Texture2DAtlas>("atlas");
Sprite sprite = atlas.CreateSprite("run_side_0000");
sprite.Effect = SpriteEffects.None;
spriteBatch.Begin(samplerState: SamplerState.PointClamp);
spriteBatch.Draw(sprite, new Vector2(400, 300), 0f, Vector2.One * 2f);
spriteBatch.End();For animation, create or retrieve one Sprite for each indexed frame and draw the current one in order. Replace .png in the generated asset paths with the image extension selected for the export.