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.dll
to your MGCB using the Monogame Pipeline Tool. -
Create an new file with
.box
extension. 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
.box
file 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
.xnb
with filename matching your original.box
file. Load this file at runtime.b. The serialized, packed texture with filename matching
<name>Texture.xnb
c. A
<name>.png
representing the same packed texture, but in a format you may preview.
-
Load a sprite sheet using
ContentManager
. Use the.box
filename here.SpriteSheet mySpriteSheet = Content.Load<SpriteSheet>( "myAssetName" );
-
Draw sprites using the
SpriteBatchExtensions
method. The center of the sprite will be drawn at the position specified.spriteBatch.Draw( mySpiteSheet.Sprites["someSpriteName"], position: new Vector2(50f, 120f) );