### Get TexturePacker Command Line Help Source: https://www.codeandweb.com/texturepacker/documentation/commandline Run the TexturePacker command with the --help flag to display a list of all available parameters and their descriptions. ```bash TexturePacker --help ``` -------------------------------- ### Create TexturePacker Dockerfile Source: https://www.codeandweb.com/texturepacker/documentation/docker-ci Installs TexturePacker and its dependencies on Ubuntu 24.04. Ensure TexturePacker.deb is in the same directory. Uncomment the license agreement line if you agree to the terms. ```dockerfile FROM ubuntu:24.04 ARG DEBIAN_FRONTEND=noninteractive RUN apt update RUN apt -y install \ libfontconfig \ libx11-6 \ libxkbcommon-x11-0 \ libglib2.0-0 \ libdbus-1-3 \ libgssapi-krb5-2 \ libgl1 \ libegl1 \ libegl-mesa0 # Install TexturePacker COPY TexturePacker.deb /tmp RUN apt -y install /tmp/TexturePacker.deb # Uncomment this line if you agree to the license terms # RUN echo agree | TexturePacker --version ``` -------------------------------- ### Run TexturePacker via Flatpak CLI Source: https://www.codeandweb.com/texturepacker/documentation/installation-and-licensing Execute TexturePacker from the command line after installation via Flatpak. This command launches the application. ```bash flatpak run com.codeandweb.texturepacker ``` -------------------------------- ### Template Loop Example Source: https://www.codeandweb.com/texturepacker/documentation/custom-exporter Demonstrates how to iterate over a list in a template using the 'for' loop tag. Each item in 'mylist' will be rendered with a preceding hyphen and space. ```django {% for item in mylist %} - {{ item }} {% endfor %} ``` -------------------------------- ### Install TexturePacker on Debian/Ubuntu via CLI Source: https://www.codeandweb.com/texturepacker/documentation/installation-and-licensing Use this command to install the TexturePacker .deb package on Debian-based Linux distributions using the apt package manager. ```bash sudo apt install ./TexturePacker-7.12.0.deb ``` -------------------------------- ### Basic TexturePacker Template Syntax Source: https://www.codeandweb.com/texturepacker/documentation/custom-exporter A simple template example demonstrating comments, variable substitution, and conditional logic using 'if', 'else', and 'endif' tags. Comments are ignored during rendering. ```django {# A simple template example #} Hello {{ person.name }}, {% if person.hasBirthday %} Happy Birthday! {% else %} Have a nice day! {% endif %} Bye, {{ myname }} ``` -------------------------------- ### Add Flathub Repository for Flatpak Source: https://www.codeandweb.com/texturepacker/documentation/installation-and-licensing If the Flatpak installation fails due to a missing runtime, add the Flathub repository. This command ensures the necessary base runtime is available. ```bash flatpak remote-add --if-not-exists flathub https://flathub.org/repo/flathub.flatpakrepo ``` -------------------------------- ### Install TexturePacker via Flatpak Source: https://www.codeandweb.com/texturepacker/documentation/installation-and-licensing Install TexturePacker using the Flatpak package manager. This method is suitable for various Linux distributions. ```bash flatpak install TexturePacker-7.12.0.flatpak ``` -------------------------------- ### Install TexturePacker Command Line Tool on macOS Source: https://www.codeandweb.com/texturepacker/documentation/commandline Create a symbolic link to the TexturePacker executable in a directory included in your system's PATH. This allows you to run TexturePacker from the command line. ```bash sudo ln -s "/Applications/TexturePacker.app/Contents/MacOS/TexturePacker" "/usr/local/bin/TexturePacker" ``` -------------------------------- ### Update TexturePacker Project File Settings Source: https://www.codeandweb.com/texturepacker/documentation/commandline Modify settings within a .tps project file from the command line without opening the UI. This example updates padding settings and saves the changes back to the same file. ```bash TexturePacker project.tps --padding 10 --save project.tps ``` -------------------------------- ### Activate License via Command Line Source: https://www.codeandweb.com/texturepacker/documentation/docker-ci Pass the license key directly to the TexturePacker executable during each execution. ```bash TexturePacker --activate-license TP-????-????-????-???? --sheet sheet.png --data sheet.json ..... ``` -------------------------------- ### Setting Up JavaScript Support in Exporters Source: https://www.codeandweb.com/texturepacker/documentation/custom-exporter Instructions on how to add JavaScript capabilities to a TexturePacker exporter by creating specific directories and using the .qs file extension. ```APIDOC ## Enhancing the Exporter with JavaScript While templates are powerful, sometimes you need more advanced functionality - such as complex calculations or data transformations. In these cases, you can enhance your exporter with JavaScript. ### Setting Up JavaScript Support To add JavaScript capabilities to your exporter: 1. Create two nested directories inside your exporter folder: * First create a **grantlee** directory * Then create a **0.2** directory inside it Your folder structure should look like this: 2. Place your JavaScript file(s) in the **grantlee/0.2** directory 3. Use the **.qs** extension for your JavaScript files ``` -------------------------------- ### Convert with Combined Options Source: https://www.codeandweb.com/texturepacker/documentation/image-conversion Applies multiple processing steps including trimming, scaling, and PVR-specific compression settings. ```bash TexturePacker --convert-texture diffuse.png diffuse.pvr \ --pixel-format PVRTCII_2BPP --pvr-quality 5 \ --trim --scale 0.5 ``` -------------------------------- ### Run TexturePacker to Accept License Source: https://www.codeandweb.com/texturepacker/documentation/docker-ci Executes TexturePacker within the container to prompt for license agreement. This is a necessary step before using the image for packing. ```bash docker run texturepacker:latest TexturePacker ``` -------------------------------- ### Texture Configuration CLI Flags Source: https://www.codeandweb.com/texturepacker/documentation/texture-settings Configuration options for defining texture formats, output file paths, and optimization settings via the command line. ```APIDOC ## Texture Format Configuration ### Description Sets the output image file format for the sprite sheet. ### Parameters #### Query Parameters - **--texture-format** (string) - Required - The ID of the format (e.g., png, jpg, webp, pvr3, ktx2, etc.) --- ## Texture File Path ### Description Defines the absolute path for the generated texture file. Supports placeholders for multipack or scaling variants. ### Parameters #### Query Parameters - **--sheet** (string) - Required - Absolute path to the output file. Use {v} for scaling variants and {n}/{n1} for multipack indices. --- ## PNG Optimization ### Description Configures lossless optimization effort for PNG output. Only applicable when --texture-format is set to png. ### Parameters #### Query Parameters - **--png-opt-level** (integer) - Optional - Value from 0 to 7. Default is 1. --- ## Image Quality Settings ### Description Sets quality parameters for lossy texture formats. ### Parameters #### Query Parameters - **--jpg-quality** (integer) - Optional - 0 to 100 (default: 80) - **--webp-quality** (integer) - Optional - 0 to 100 for lossy, >100 for lossless - **--pvr-quality** (integer) - Optional - 0 to 7 (default: 3) - **--etc1-quality** (integer) - Optional - 0 to 100 (default: 70) - **--etc2-quality** (integer) - Optional - 0 to 100 (default: 70) - **--astc-quality** (integer) - Optional - 0 to 4 (default: 2) - **--basisu-quality** (integer) - Optional - 0 to 4 (default: 2) - **--dxt-mode** (string) - Optional - DXT_LINEAR or DXT_PERCEPTUAL ``` -------------------------------- ### Build TexturePacker Docker Image Source: https://www.codeandweb.com/texturepacker/documentation/docker-ci Builds the Docker image tagged as texturepacker:latest. This command should be run in the directory containing the Dockerfile. ```bash docker build -t texturepacker:latest . ``` -------------------------------- ### Process Multiple TexturePacker Projects Source: https://www.codeandweb.com/texturepacker/documentation/commandline Process multiple .tps project files sequentially from the command line. ```bash TexturePacker sheet1.tps sheet2.tps sheet3.tps .... ``` -------------------------------- ### Override output format via command line Source: https://www.codeandweb.com/texturepacker/documentation/user-interface-overview Use the command line client to publish a project with a different image format than the one defined in the .tps file. ```bash TexturePacker main.tps --sheet ".../{n}.webp" --texture-format webp ``` -------------------------------- ### Run TexturePacker with License and Mount Source: https://www.codeandweb.com/texturepacker/documentation/docker-ci Processes sprite sheets using TexturePacker inside the Docker container. It activates the license and uses a bind-mount to access sprite sheet directories. Replace [YOUR-LICENSE-KEY] with your actual license key. ```bash docker run texturepacker:latest \ --mount type=bind,source=/tmp/spritesheets,target=/spritesheets \ TexturePacker --activate-license [YOUR-LICENSE-KEY] /spritesheets/*.tps ``` -------------------------------- ### TexturePacker CLI Usage Syntax Source: https://www.codeandweb.com/texturepacker/documentation/image-conversion Basic command-line syntax for converting textures using either an explicit output filename or a format flag. ```bash TexturePacker --convert-texture [] [options] TexturePacker --convert-texture --texture-format [options] ``` -------------------------------- ### Process All .tps Files in Directory (macOS/Linux) Source: https://www.codeandweb.com/texturepacker/documentation/commandline On macOS and Linux, use a wildcard to process all .tps files in the current directory sequentially. ```bash TexturePacker *.tps ``` -------------------------------- ### Convert PNG to KTX Source: https://www.codeandweb.com/texturepacker/documentation/image-conversion Performs a basic conversion from a PNG file to a KTX file. ```bash TexturePacker --convert-texture sprite.png sprite.ktx ``` -------------------------------- ### Process TexturePacker Projects from Command Line Source: https://www.codeandweb.com/texturepacker/documentation/commandline Execute TexturePacker projects saved as .tps files directly from the command line. This command processes a single .tps file. ```bash TexturePacker sheet.tps ``` -------------------------------- ### Implement conditional logic in templates Source: https://www.codeandweb.com/texturepacker/documentation/custom-exporter Use if/else blocks to conditionally render content based on template variables. ```text {% if condition %} Content to render when condition is true {% else %} Content to render when condition is false {% endif %} ``` -------------------------------- ### Set TP_FLOATING_LICENSE Environment Variable Source: https://www.codeandweb.com/texturepacker/documentation/docker-ci Configure the license key via environment variables to avoid hardcoding it in build scripts. ```bash export TP_FLOATING_LICENSE="TP-????-????-????-???? ``` ```cmd set TP_FLOATING_LICENSE=TP-????-????-????-???? ``` ```powershell $env:TP_FLOATING_LICENSE="TP-????-????-????-???? ``` -------------------------------- ### Add TexturePacker to Windows PATH Source: https://www.codeandweb.com/texturepacker/documentation/commandline Add the TexturePacker bin directory to your system's PATH environment variable to run it from any command prompt. This can be done temporarily in scripts or permanently through system settings. ```batch SET "PATH=C:\Program Files\CodeAndWeb\TexturePacker\bin;%PATH%" ``` -------------------------------- ### Convert with Specific Pixel Format Source: https://www.codeandweb.com/texturepacker/documentation/image-conversion Converts a PNG to KTX while explicitly setting the ASTC block size. ```bash TexturePacker --convert-texture sprite.png sprite.ktx --pixel-format ASTC_6x6 ``` -------------------------------- ### Template Variable Lookup with Dot Notation Source: https://www.codeandweb.com/texturepacker/documentation/custom-exporter Illustrates using dot notation for variable lookups in templates, including accessing list elements by index (0-indexed), hash map values by key, and object properties. ```django The first item is {{ mylist.0 }}, and the fifth item is {{ mylist.4 }}. It can also be used for key lookups: The hash value is {{ myhash.mykey }}. And it can retrieve properties from object instances: The object property is {{ myobj.myprop }}. ``` -------------------------------- ### Convert Using Texture Format Flag Source: https://www.codeandweb.com/texturepacker/documentation/image-conversion Converts an image to Basis Universal format; the output filename is automatically derived from the input. ```bash TexturePacker --convert-texture sprite.png --texture-format basis --basisu-quality 3 ``` -------------------------------- ### Texture Settings - Data Options Source: https://www.codeandweb.com/texturepacker/documentation/texture-settings Configuration options related to the data output of TexturePacker. ```APIDOC ## Data Format ### Description Sets the Data Format or framework for the project, enabling additional features. Can be changed after project creation. ### Method N/A (Configuration setting) ### Endpoint N/A ### Parameters #### Command Line - `--format ` (string) - Required - The name of the data format/framework. ### Request Example ``` --format ``` ## Data File ### Description Specifies the output file name for the Data file, which contains sprite metadata. Supports placeholders for multipack and scaling variants. ### Method N/A (Configuration setting) ### Endpoint N/A ### Parameters #### Command Line - `--data ` (string) - Required - The absolute path for the output Data file. Use placeholders like `{v}` for scaling variants and `{n}` or `{n1}` for multipack indices. ### Request Example ``` --data ``` ## Additional Data Files ### Description Allows exporting a second data file for sprite IDs and other metadata, depending on the framework. ### Method N/A (Configuration setting) ### Endpoint N/A ### Parameters #### Command Line - `--class-file ` (string) - Optional - Swift class output file (spritekit-swift). - `--classfile-file ` (string) - Optional - C# class output file (monogame). - `--header-file ` (string) - Optional - C++/ObjC header output file (cocos2d-x, spritekit, plain). - `--source-file ` (string) - Optional - C++ source output file (cocos2d-x). - `--spriteids-file ` (string) - Optional - Rust sprite id output file (amethyst). ### Request Example ``` --class-file --header-file ``` ## Trim Sprite Names ### Description Removes image file extensions (e.g., .png, .tga) from sprite names. ### Method N/A (Configuration setting) ### Endpoint N/A ### Parameters #### Command Line - `--trim-sprite-names` (boolean) - Optional - Flag to enable trimming of sprite name extensions. ### Request Example ``` --trim-sprite-names ``` ## Prepend Folder Name ### Description Prepends the smart folder's name as part of the sprite name. Sub-folder names are always included. ### Method N/A (Configuration setting) ### Endpoint N/A ### Parameters #### Command Line - `--prepend-folder-name` (boolean) - Optional - Flag to enable prepending folder names to sprite names. ### Request Example ``` --prepend-folder-name ``` ## Auto-detect Animations ### Description Automatically defines animations in the data file for sprites with the same base name and a numerical suffix (e.g., `walk_001.png`, `walk_002.png`). Only available for specific frameworks. ### Method N/A (Configuration setting) ### Endpoint N/A ### Parameters #### Command Line - (No direct command-line option mentioned, typically a GUI setting) ### Request Example (GUI setting, no direct command-line example) ## Texture Path ### Description Prepends a path before the file name of the texture in the Data file. Useful for storing sprite sheet images separately. ### Method N/A (Configuration setting) ### Endpoint N/A ### Parameters #### Command Line - `--texturepath ` (string) - Optional - The path to prepend to texture file names. ### Request Example ``` --texturepath /assets ``` ## Filtering (LibGDX) ### Description Sets the filtering values specifically for the LibGDX exporter. ### Method N/A (Configuration setting) ### Endpoint N/A ### Parameters #### Command Line - (Specific filtering options not detailed in the provided text) ### Request Example (Specific filtering options not detailed in the provided text) ``` -------------------------------- ### Template Conditional Logic with List Check Source: https://www.codeandweb.com/texturepacker/documentation/custom-exporter Shows how to use 'if' and 'else' tags to conditionally render content based on whether a list is empty or not. An empty list evaluates to 'false'. ```django {% if mylist %} List items: {% for item in mylist %} - {{ item }} {% endfor %} {% else %} The list is empty. {% endif %} ``` -------------------------------- ### Convert Image Format with TexturePacker Source: https://www.codeandweb.com/texturepacker/documentation/commandline Use this command to convert an input image to a specified output format, such as ASTC. For more details on supported formats and options, refer to the Image conversion page. ```bash TexturePacker --convert-texture input.png output.astc ``` -------------------------------- ### Pack Sprite Sheets for Phaser Source: https://www.codeandweb.com/texturepacker/documentation/commandline Use this command to pack sprites from a folder into a sprite sheet image and a corresponding data file, specifying the output format, sheet file name, and data file name. ```bash TexturePacker --format phaser --sheet out.png --data out.json spritefolder ``` -------------------------------- ### Override .tps Settings with Command Line Arguments Source: https://www.codeandweb.com/texturepacker/documentation/commandline Load settings from a .tps file and override specific parameters like output sheet and data file names, and input sprite folders directly on the command line. ```bash TexturePacker configuration.tps --sheet mysheet.png --data mysheet.json sprites ``` -------------------------------- ### Access List Item and Apply Filter Source: https://www.codeandweb.com/texturepacker/documentation/custom-exporter Access elements in a list using index notation and apply filters. Ensure the index is valid for the list. ```django First person's name: {{ people.0.name|upper }}. ``` -------------------------------- ### Ignore Files and Directories in TexturePacker Source: https://www.codeandweb.com/texturepacker/documentation/hidden-features Configure TexturePacker to exclude specific files or directories from being packed. Add a `` entry for each pattern to ignore. ```xml ignoreFileList ``` ```xml ignoreFileList *.psd */test/* ``` -------------------------------- ### Create JavaScript Filters for Multi-Parameter Operations Source: https://www.codeandweb.com/texturepacker/documentation/custom-exporter Use global variables to pass values between sequential filters when direct multi-parameter input is not supported. One filter stores a value globally, and another uses it for calculations. Ensure filters return an empty string if they should not output any value. ```javascript // Define a global variable width = 1; // First filter: stores a value for later use var SetWidth = function (input) { width = input; // store the value globally return ""; // return empty string (won't appear in output) }; SetWidth.filterName = "setWidth"; Library.addFilter("SetWidth"); // Second filter: uses the stored global value var MakeRelX = function (input) { return String(input / width); // calculate relative position }; MakeRelX.filterName = "makeRelX"; Library.addFilter("MakeRelX"); ``` ```django {{ texture.size.width|setWidth }}{{ sprite.frameRect.x|makeRelX }} ``` -------------------------------- ### Iterate over collections with loops Source: https://www.codeandweb.com/texturepacker/documentation/custom-exporter Use the for loop structure to process lists of items like sprites. ```text {% for item in itemList %} Content to render for each item Current item: {{ item }} {% endfor %} ``` -------------------------------- ### Chain Multiple Filters Source: https://www.codeandweb.com/texturepacker/documentation/custom-exporter Apply multiple filters sequentially to a variable. The output of one filter becomes the input for the next. ```django Name is {{ name|upper|lower }} ``` -------------------------------- ### Define a sprite sheet data template Source: https://www.codeandweb.com/texturepacker/documentation/custom-exporter This template iterates through all sprites to output frame coordinates, rotation status, and source dimensions. ```text // Created with TexturePacker (https://www.codeandweb.com/texturepacker) // // Sprite sheet: {{ texture.fullName }} ({{ texture.size.width }} x {{ texture.size.height }}) // // {{ smartUpdateKey }} sprites = [ {% for sprite in allSprites %} {{ sprite.trimmedName }} = [ frame = [ {{ sprite.frameRect.x }}, {{ sprite.frameRect.y }}, {{ sprite.frameRect.width }}, {{ sprite.frameRect.height }} ], rotated = {{ sprite.rotated }}, source = [ {{ sprite.cornerOffset.x }}, {{ sprite.cornerOffset.y }}, {{ sprite.untrimmedSize.width }}, {{ sprite.untrimmedSize.height }} ] ] {% if not forloop.last %}, {% endif %} {% endfor %} ] ``` -------------------------------- ### Iterate Over All Sprites Source: https://www.codeandweb.com/texturepacker/documentation/custom-exporter Use this loop to iterate over all sprites, including alias sprites, in TexturePacker. This is generally more convenient than iterating over unique sprites. ```twig {% for sprite in allSprites %} ... {% endfor %} ``` -------------------------------- ### Load a JavaScript Filter in a Template Source: https://www.codeandweb.com/texturepacker/documentation/custom-exporter Use the `load` tag in your template to make a registered JavaScript filter available. The tag argument must match the JavaScript file name without the extension. ```django {% load makecssselector %} ``` -------------------------------- ### Set TexturePacker PATH on macOS/Linux Source: https://www.codeandweb.com/texturepacker/documentation/commandline Alternatively, set the PATH environment variable in your build scripts or shell configuration files to include the directory containing the TexturePacker executable. ```bash export PATH="/Applications/TexturePacker.app/Contents/MacOS/:$PATH" ``` -------------------------------- ### Loop and Auto-Escape HTML Output Source: https://www.codeandweb.com/texturepacker/documentation/custom-exporter Iterate over a list and display its items. The template engine automatically escapes HTML special characters in the output. ```django {% for company in companies %} - {{ company }} {% endfor %} ``` -------------------------------- ### Replace File Names and Remove Path Prefixes in TexturePacker Source: https://www.codeandweb.com/texturepacker/documentation/hidden-features Modify sprite names by replacing parts of file names or removing directory prefixes. Use Perl-style regular expressions for replacements. ```xml replaceList ``` ```xml replaceList .*/= ```