Pack My Sprites is a program that generates sprite sheets from a collection of images made with Gimp. The process does not requires the user to produce any intermediate image files. Thus, all you have to do is drawing the image and listing which layers to use for each sprite, then the program will generate the sprite sheet from it. Pack My Sprites makes the modifications on the source images costless for the project. It was especially used during the production of Andy's Super Great Park.
Download
Pack My Sprites is available in source code form also on GitHub. It is written in C++.
Claw, Boost, CMake and docbook-to-man are required to compile the program. Gimp and Xcftools are required at run-time to process the images.
Presentation
A sprite packing software is a useful tool in game development and typically builds a large image file from several smaller image files. See for example Sprite Sheet Packer or TexturePacker among others.
As a 2D artist I am really bored by the steps I have to follow before I can see my drawings in the final product. Unfortunately, the classic sprite packing softwares ask me to follow the following steps each time I make a change in my source images:
- Resize the image to its final size,
- Select the layers of the sprite, hide the others,
- Export the image into a PNG file,
- Repeat the above two steps for each sprite,
- Launch the packer, select the images,
- Generate the large image.
Each of these steps is repetitive and useless, thus should be automatized. A first step toward automatization is to have a command line tool instead of a graphical interface. On this point, glue is going in the right direction, but it is not enough.
I want a sprite packing software that works with my source images: the XCF files I create with Gimp!
The purpose of Pack My Sprites is to reduce the time required to integrate graphic updates into the final product. In order to achieve this goal, Pack My Sprites automates the generation of the sprites and helps its integration in the build process of the product.
The default behavior of the program is to parse an input text file to generate some sprite sheets and a listing of the localization of their sprites. The input file must describe each sprite with a unique name, the layers to show to build them, and their final size in the sprite sheet. The output is a PNG file containing each sprite and a text file associating the position and the size of each sprite with its name. See the input format for details about the syntax of the input file.
Eventually, Pack My Sprites can also generate a makefile whose rules build the sprite sheets, with dependencies on the XCF files and the input text file.
The software relies upon the gimp-console and xcfinfo programs for the generation of the sprite sheets.
Usage example 1
This example uses an animation of the flying bird from Andy's Super Great Park and is available in the download. Here is a capture of the image in Gimp:
To produce the sprite sheet from this image and another one, I write the following file:
Then I execute the following command to generate the sprite sheet:
The command produce two files. The sprite sheet:
and a file containg the localization of the sprites in the sprite sheet:
Usage example 2
Here is another example of input file:
The processing of this file will produce two outputs: an image named letters-1.png and a text file named letters-1.spritepos. The latter contains the following localization of the sprites in the image:
Input Format
The input files can contain one or several sprite sheets. Each one begins with the sprite_sheet keyword, followed by the name of the sprite sheet and the maximum size of the output image, according to the following syntax:
The margin M optional argument allows to define the spacing between the sprites in the output. The default value is 1.
The order "O" optional argument allows to force a given heuristic for the placement of the sprites in the output. The default value is "area", which considers the sprites in decreasing order of their area. Other possible values are "height" to select the sprites by decreasing order of their height or "none" to consider the sprites in their declaration order.
Following the header is a list of XCF files used to build the sprites:
Then come the sprites, defined by a name, a size, a source image, a selection of layers and an optional mask:
The reference_box can be the name of a layer from the source image, or one of the following special values:
- autosize
- The box is the smallest one that contains all the selected layers.
- image_size
- The box is the one of the canvas in the input image.
The scale_factor is a positive value that determine the size of the sprite in the output. For example, a value of 0.5 will produce a sprite half the size of the reference box.
The layer selection has different formats:
- "layer_name"
- Selects the layer with the given name in the source image.
- glob "pattern"
- Selects all layers whose name match the given pattern. The
pattern can contain the following special charaters:
- *
- Matches any sequence of symbols, empty sequences included.
- .
- Matches a single symbol.
- ?
- Matches zero or one symbol.
- exclude "layer_name"
- Forces the layer with the given name in the source image not to be selected. This is useful to remove a layer from a glob expression.
- exclude glob "pattern"
- Forces the layers whose name match the given pattern not to be selected.
The optional mask instruction tells to use the layer with the given name as a mask in the resulting sprite. The white parts of the layer will be opaque in the resulting sprite, while the black parts will be fully transparent. Intermediate grey values will be partially transparent.
License
Pack My Sprites is written by Julien Jorge <julien.jorge@gamned.org>. It is hereby licenced under the terms of the version 3 of the GNU General Public Licence.