FreeTexturePacker.Lib
1.0.0
dotnet add package FreeTexturePacker.Lib --version 1.0.0
NuGet\Install-Package FreeTexturePacker.Lib -Version 1.0.0
<PackageReference Include="FreeTexturePacker.Lib" Version="1.0.0" />
paket add FreeTexturePacker.Lib --version 1.0.0
#r "nuget: FreeTexturePacker.Lib, 1.0.0"
// Install FreeTexturePacker.Lib as a Cake Addin #addin nuget:?package=FreeTexturePacker.Lib&version=1.0.0 // Install FreeTexturePacker.Lib as a Cake Tool #tool nuget:?package=FreeTexturePacker.Lib&version=1.0.0
Free Texture Packer Loader
A sprite sheet loader for using Free Texture Packer with Monogame
Read in another language : English, Français
Structure
There are four main classes to look at :
SpriteFrame
: it represent one image inside of a spritesheetSpriteSheet
: it represent the a collection on spriteframeSpriteSheetLoader
: it is used to load the spritesheet generated from Free Texture PackerSpriteRender
: it draws a sprite to the screen
The other classes are used to store information about a SpriteFrame:
Pivot
stores the pivot point of a frameRect
store the (X,Y) position of an image inside of a sritesheet and that image size (Width, Height)Size
store the size (With, Height) of the image
Getting started
Prerequisites
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
Installing
You have two ways to install it in your project
Use the sources
Simply copy theFreeTexturePackerLoader
folder in your monogame projectGet IT through Nuget
dotnet add package FreeTexturePacker.Lib --version 1.0.0
Using Free Texture Packer to create a spritesheet
Open Free Texture Packer
Add the images in the
Examples/images
folderSet texture name to
chess
Set texture format to
png
Check the
Remove file ext
boxFor the packer use
OptimalPacker
Uncheck
Allow trim
boxFor the format, choose
custom
Click the little pencil next to it
Paste the following export template :
{ "name":"{{{config.imageName}}}", "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 trim
andAllow rotation
boxesFor file extension, write
json
Click
Save
Click
Export
Locate the Content directory of your monogame project and click
Select Folder
It'll generate two files: chess.json
and chess.png
.
The first contains informations about the spritesheet such as the posistion and size all the images inside that spritesheet and the last file is the actual spritesheet.
Loading the spritesheet and using it with monogame
Create a monogame desktop project
Copy the
FreeTexturePackerLoader
folder inside of your monogame project or add it through nugetAt this using line at the top of your Game1.cs file
using FreeTexturePackerLoader;
Create an instance of the SpriteSheetLoader in the
LoadContent
methodvar spriteSheetLoader = new SpriteSheetLoader(Content);
Create aninstance of the SpriteRenderer
private SpriteRender spriteRender;
In the
LoadContent
method, add :spriteRender = new SpriteRender(_spriteBatch);
Load the spritesheet
private SpriteSheet spriteSheet;
In the
LoadContent
method, add :spriteSheet = spriteSheetLoader.Load("chess");
Draw a sprite from the spritesheet In the
Draw
method, add :spriteRender.Draw(spriteSheet.GetSprite("reine_blanc"), new Vector2(100, 100), Color.White);
You should see the white queen at the screen
Now try to show all the chess piece at the screen.
You can find the full project in the
Example/ChessBoard Final
Contributing
Please read CODE_OF_CONDUCT.md for details on our code of conduct, and the process for submitting pull requests to us.
Authors
- Sesso Kosga - Initial work - senor16
License
This project is licensed under the MIT License - see the licence.md file for details
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
-
net6.0
- MonoGame.Framework.DesktopGL (>= 3.8.1.303)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
1.0.0 | 246 | 1/28/2023 |