A Monogame content pipeline extension for combining many individual sprites into a single texture.
Add a reference to the SpriteBox pipeline extension assembly using the Monogame Pipeline Tool. Get the assembly with:
nuget install Monogame.SpriteBox.PipelineExtension
Add the SpriteBox runtime to your game project to enable loading of content produced by the pipeline extension.
nuget install Monogame.SpriteBox
-
Add
Monogame.SpriteBox.PipelineExtension.dllto your MGCB using the Monogame Pipeline Tool. -
Create an new file with
.boxextension. Populate it with a name and path information hinting at which sprites you'd like to pack. Note, the path hints support Glob patterns for convenience.Schema
{ "Name" : string, "PathPatterns" : [ string ] }Example
{ "Name": "Environment", "PathPatterns": [ "Backgrounds/BG1.png", "Dungeons/Floors/**/*", "Dungeons/Walls/*.png", "Overworld/**/*.png ] } -
Add the
.boxfile to your MGCB the same way other assets are. Optionally, set the processor parameters documented in the code. -
Build to produce:
a. The serialized SpriteBox
.xnbwith filename matching your original.boxfile. Load this file at runtime.b. The serialized, packed texture with filename matching
<name>Texture.xnbc. A
<name>.pngrepresenting the same packed texture, but in a format you may preview.
-
Load a sprite sheet using
ContentManager. Use the.boxfilename here.SpriteSheet mySpriteSheet = Content.Load<SpriteSheet>( "myAssetName" ); -
Draw sprites using the
SpriteBatchExtensionsmethod. The center of the sprite will be drawn at the position specified.spriteBatch.Draw( mySpiteSheet.Sprites["someSpriteName"], position: new Vector2(50f, 120f) );