Skip to content

A Monogame content pipeline extension for combining many individual sprites into a single texture.

License

Notifications You must be signed in to change notification settings

scott-lin/Monogame.SpriteBox

Repository files navigation

Monogame.SpriteBox

Azure DevOps builds (branch) Nuget Nuget

A Monogame content pipeline extension for combining many individual sprites into a single texture.

Setup

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

Usage

Pipeline Extension

  1. Add Monogame.SpriteBox.PipelineExtension.dll to your MGCB using the Monogame Pipeline Tool.

  2. 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
             ]
     }
    
  3. Add the .box file to your MGCB the same way other assets are. Optionally, set the processor parameters documented in the code.

  4. 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.

Runtime

  1. Load a sprite sheet using ContentManager. Use the .box filename here.

    SpriteSheet mySpriteSheet = Content.Load<SpriteSheet>( "myAssetName" );
    
  2. 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) );
    

About

A Monogame content pipeline extension for combining many individual sprites into a single texture.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages