A Monogame content pipeline extension to load spritesheets generated from Free Texture Packer into Monogame
Read in another language : English, Français
Getting started
Prerequisites
Installing
Using Free Texture Packer to create a spritesheet
Adding the extension to the content pipeline
Loading the spritesheet and using it in a monogame project
Contributing
Versioning
Authors
License
Acknowledgments
You must have Monogame installed.
For this example, I'm using Monogame 3.8.1.303
You must also have Free Texture Packer installed
For this example, I'm using Free Texture Packer 0.6.7
You need two nuget packages : FreeTexturePackerReader and FreeTexturePackerPipeline
dotnet add package FreeTexturePackerReader --version 1.0.0
dotnet add package FreeTexturePackerPipeline --version 1.0.0
-
Open Free Texture Packer
-
Add the images in the
imagesfolder -
Set texture name to
chess -
Set texture format to
png -
Check the
Remove file extbox -
For the format, choose
custom -
Click the little pencil next to it
-
Paste the following export template :
{ "name":"{{{config.imageName}}}", "texture":"{{{config.imageName}}}.png", "frames":[ {{#rects}} { "filename":"{{{name}}}", "frame":{ "X":{{frame.x}}, "Y":{{frame.y}}, "Width":{{frame.w}}, "Height":{{frame.h}} }, "rotated":{{rotated}}, "trimmed":{{trimmed}}, "spriteSourceSize":{ "X":{{spriteSourceSize.x}}, "Y":{{spriteSourceSize.y}}, "Width":{{spriteSourceSize.w}}, "Height":{{spriteSourceSize.h}} }, "sourceSize":{ "Width":{{sourceSize.w}}, "Height":{{sourceSize.h}} }, "pivot":{ "X":0.5, "Y":0.5 } }{{^last}},{{/last}} {{/rects}} ], "meta":{ "app":"{{{appInfo.url}}}", "version":"{{{appInfo.version}}}", "image":"{{{config.imageName}}}", "format":"{{{config.format}}}", "size":{ "Width":{{config.imageWidth}}, "Height":{{config.imageHeight}} }, "scale":{{config.scale}} } } -
Check
Allow trimandAllow rotationboxes -
For file extension, write
spritesheet -
Click
Save -
Click
Export -
Choose a folder and click
Select Folder
- Create a monogame desktop project
- Add the pipeline extension to your project (see Installing)
- Open
Content.mgcb - Click on
Content - Under
Properties, scroll down toReferenceand click it - Click
Add - Locate the .dll for the extension pipeline.
You'll find it from the root of you game project in the folder\bin\Debug\net6.0\FreeTexturePackerPipeline.dll - Click
Ok
-
Copy the spritesheet files your exported :
chess.pngandchess.spritesheet(see Using Free Texture Packer to create a spritesheet) into the Content folder of your game project -
Right click on
ContentthenAdd>Existing Item... -
Select
chess.spritesheetthen clickOpen -
Got to
Build>Buildor pressF6 -
Open your
Game.csand add this using at the topusing FreeTexturePackerReader; -
Load the spritesheet
In theLoadContentmethod, add :chess = Content.Load<SpriteSheet>("chess"); -
Draw a sprite at the screen
In theDrawmethod, add :_spriteBatch.Begin(); var sprite = chess.frames["reine_blanc"]; _spriteBatch.Draw(chess.Texture,new Vector2(100,100),sprite.sourceRect,Color.White,sprite.rotation,sprite.origin,1,SpriteEffects.None,1); _spriteBatch.End(); -
Run the game
You'll find the sample project in the SampleGame folder
Please read CODE_OF_CONDUCT.md for details on our code of conduct, and the process for submitting pull requests to us.
We use SemVer for versioning.
- Sesso Kosga - Initial work - sessokosga
This project is licensed under the MIT License - see the licence.md file for details
Thanks to :
- Ragath for his suggestion to implement the lib I had made into this Monogame Pipeline extension
You made me discover a part of the monogame framework that I did'nt knew. - Matt Weber for his toturial on How to extend Monogame's content pipeline
Your tutorial helped me to deepen my understanding of the monogame content pipeline - RB Whitaker's Wiki for his tutorial on Building a content pipeline extension
Your tutorial helped to fix a bug that has caused me terrible headache