UPDATE: A few people have asked, so we’ve released the source code for the tool in the download links below. We’re unable to make any modifications to it, as we’re no longer developing the tool internally, but feel free to modify it for your own needs, and contact us if you need any help with it. Unfortunately, the code isn’t the tidiest code around. Please note that all source and binary code is provided “as is”, without any warranty of any kind. Please see the website usage terms, at the bottom of the page, for more information.
A texture atlas, or sprite sheet, is a single image containing a number of smaller textures or sprites. This is useful as it is more efficient for the graphics card to process (it doesn’t have to keep switching textures when drawing different textures, as it can just use the single texture and sample from different parts of it). It is also faster to load into RAM, as you are only loading in one image, as opposed to several smaller ones, so the loading can be done in one stage.
NOTE: The documentation for the TXA file format states that the first value in the file is the number of sprites. In fact, the tool was updated to store the dimensions of the generated image as the first two ints in the file, followed by the format as described in the documentation. The documentation hasn’t been updated to reflect this, so be careful!
It is useful to be able to quickly and easily generate texture atlases from a number of source sprites to speed up development. A useful tool when developing using the XNA framework is the SpriteSheet Sample available on the XNA Creators Club website. One downside of this, however, is that you must still manually generate the XML file list by hand, which can be a pain if you have a lot of textures to place on the sprite sheet. Another is that it is XNA only
Because we also do development on the iPhone, it was useful to have a similar generator for that platform, as well as for the XNA framework, so we created a tool to easily generate the texture atlases for us. The packing code is based on the SpriteSheet Sample code, though the tool is written in plain .NET, so does not require the XNA framework to be installed (though it does require the .NET framework). The tool can produce a PNG file with the combined textures, as well as an accompanying binary file, called a TXA file, with the information on each of the packed textures. It also supports removing transparent borders from textures to produce a more compact output. It can also optionally produce a C style header with enums in, so you don’t have to look up the textures by their names.
The help files for the texture atlas generator tool contain information on the format of the TXA files, so you can write your own loaders if you wish.
As well as the PNG + TXA combination, the tool can produce an XNA XML file (and optionally a C# file with enums in) which can be imported into your Content project to build the sprite sheet during compile time. You do need to include the XNA projects in yours to access the Content Processor and runtime types. The runtime library also includes extensions to the SpriteBatch class, to make it easier to draw using the textures.
Finally, there is a runtime library to load the texture atlas on an iPhone. The iPhone code uses the PVRTexture class from Apple’s sample code, so you can convert the PNG to a PVR if you wish using Apple’s texturetool (though this can be problematic as the textures may ‘bleed’ into each other). The iPhone runtime library also requires zlib and libpng
Each zip contains a Readme.txt file containing license information and other tips. You’re pretty much free to do what you want with these things, use them however you see fit (commercial or non-commercial), but remember they are provided as-is, and we accept no responsibility for anything We’ve tried to tidy them up to make them usable by other people, but if you’ve got any problems or questions, post in the comments and we’ll try and help. There may be bugs in these, so let us know if you find any!