GAME DESIGN IN LIBGDX

GUIDE – CREATING SPRITE SHEETS

separator-blank.png

DESCRIPTION

LibGDX has supports that allow you to read directly from a spritesheet.  The spritesheet needs to be accompanied by data file that describes the location of the individual sprites on the spritesheet.

While you can create your own spritesheet and data file, it is quite time consuming.  Thankfully, there are tools that can help.

GETTING STARTED

Before using a tool to create our spritesheet, we must first create or find the sprites that we want to use.  Unfortunately, often these sprites are already in their own spritesheets.  And for us to use them, we need them to be separated into individual images.

SPLITTING SPRITESHEETS

One option is to manually crop out each sprite that you want.  This can be quite time consuming as you must make sure that all sprites line up perfectly within their image. 

There are tools that exist to separate a spritesheet into many individual images.  In fact, creating a program that does this is possible inside this course!

One tool that was found on the internet is called SpriteCutter2.

SPRITECUTTER2

Click here to download the tool.  It’s not great.  And it’s a pain to get used to.  But it works. Read the help file in the program’s folder for step by step instructions.

CREATING SPRITE SHEETS FOR LIBGDX

One option to create the spreadsheet and datasheet is to use a program called TexturePacker which is available for free online.  However, its datasheet doesn’t create the exact format that LibGDX uses it seems.  Ask Mr. Campeau about this.

There is also a way to do this using LibGDX’s library.  This method will eventually be described here.  As Justin Michaud about this.
J


EXAMPLE

STEP 1

I found the following sprite sheet online.

STEP 2

I can’t use the above sprite sheet as is because it doesn’t have the required LibGDX data file with it.  While it would be possible to recreate the data file manually, that would be pretty tedious.  It’s a better option to use a tool to reconstruct the sprite sheet – however that tool requires that all images be in their own file.

STEP 3

So I’m going to break the sprite sheet apart.  Again, I could do that by manually cropping out each sprite one at a time but that would also be tedious.  So I will use SpriteCutter2.

STEP 4

Using SpriteCutter2, I now have my sprites in individual files.  Ask Mr. Campeau for help with SpriteCutter2 as it is a little messy to work with it.

STEP 5

Using the software TexturePacker (Lite edition), I recreated sprite sheet to work with LibGDx.

STEP 6

One little problem to deal with.  In the data file (nukeData.txt), all the images are given the same name.  I went ahead and added their index number to their name.  There is probably a way of working with the original file in LibGDX but I haven’t found it yet.



STEP 7

Now I simply copied both of the files to the assets folder and refreshed that folder in Eclipse and I was ready to go!

 

 

 

separator-campeau.png