Running TexturePacker from Commandline

You can easily integrate TexturePacker into your build process and run it from command line without using the graphical user interface.

Installing the command line

Windows

Open the menu File/Install Command Line Tool

Assuming that you've installed TexturePacker in the standard location, you'll have to add this path to the command line:

C:\Program Files\CodeAndWeb\TexturePacker\bin

You can do this in your scripts using

SET "PATH=C:\Program Files\CodeAndWeb\TexturePacker\bin;%PATH%"

To add the path permanently on Windows, navigate to Settings -> System -> About -> Advanced system settings -> Environment Variables. Select the Path variable and add C:\Program Files\CodeAndWeb\TexturePacker\bin.

macOS

Use the menu TexturePacker / Install Command Line Tool to get this dialog:

Installing TexturePacker's command line tool on macOS

Click Install. TexturePacker will ask you for admin permissions to set the link to TexturePacker. You can also install it manually using

sudo ln -s "/Applications/TexturePacker.app/Contents/MacOS/TexturePacker" "/usr/local/bin/TexturePacker"

if you don't want to install that link to TexturePacker you can also only set a path inside your build scripts or .zshrc or .bashrc

export PATH="/Applications/TexturePacker.app/Contents/MacOS/:$PATH"

It does not matter which way you install TexturePacker.

Linux

Nothing to do here. TexturePacker is already in the path after installing the .deb file.

Command line arguments and help

To get an overview of the command line parameters simply use

TexturePacker --help

This gives you a list of all available parameters with a short description. You can find a more in-depth explanation of the parameters in the documentation here. The headlines of each section in TextureSettings contains the parameters. (E.g. Data format --format <name>)

Packing sprite sheets

To pack a sprite sheet — e.g. for phaser — you can use the following command line:

TexturePacker --format phaser --sheet out.png --data out.json spritefolder
  • --format <name> sets the output format / the game engine you use
  • --sheet <file> sets the file name of the sprite sheet image
  • --data <file> sets the file name of the data file
  • spritefolder is the name of the folder that contains all your sprites

TexturePacker recursively collects all sprites in the spritefolder folder and adds them to your sprite sheet. You can add multiple folders at once.

You can also add individual sprites if you want more control over what is added to the sheet.

Configuring TexturePacker in the UI, building from command line

TexturePacker can also process TexturePacker projects you create in the UI. Save the .tps file and call

TexturePacker sheet.tps

It's also possible to process multiple sheets at the same time using

TexturePacker sheet1.tps sheet2.tps sheet3.tps ....

On macOS and Linux you can also use the following command line to process all .tps files in sequence (this is not supported on Windows)

TexturePacker *.tps

Using a .tps file as configuration file

Additional parameters on the command line can override the settings that TexturePacker reads from a .tps file. So you can load the packer parameters from a .tps file (don't add sprites or set output file names in the UI), and pass input and output file names on command line:

TexturePacker configuration.tps --sheet mysheet.png --data mysheet.json sprites

Updating TexturePacker project files (.tps) from command line

You can also update the .tps files with new settings from command line without opening the graphical user interface. This is useful if you want to change the same settings in many projects at once.

E.g. for updating the paddings in your project.tps:

TexturePacker project.tps --padding 10 --save project.tps

This loads the project.tps, changes the paddings and saves it again as project.tps

Running TexturePacker in your build process

TexturePacker is smart about detecting file changes and when to rebuild a sprite sheet. This is done based on time stamps and a so-called smart update hash which is stored in the sprite sheet's data file.

TexturePacker re-builds a sprite sheet if

  • a sprite has been changed, added or removed
  • settings have been changed
  • a different version of TexturePacker is used
  • the --force-publish argument is set on command line

Detecting whether a rebuild is necessary is very fast, allowing you to run TexturePacker in your build scripts without significantly slowing down the build process.

You also don't have to set all sprites as input dependencies e.g. in make. TexturePacker does that automatically for you.

Line endings

TexturePacker stores files with local file endings. That means LineFeed (LF) on macOS and Linux, CarriageReturn-LineFeed (CRLF) on Windows.

If you are using TexturePacker in a mixed environment with Windows and macOS or Linux clients, you should configure your version control system to convert between the different ending styles. See our tutorial How to handle line endings in git for more details about how you can do that.