Skip to main content

TexturePacker

AssetPack plugin for generating texture atlases using sharp.

If you are using the mipmap plugin you will want to pass the same options to the texturePacker plugin as you are to the mipmap plugin.

info

This plugin is designed to work with the spritesheet format PixiJS uses. If you are using a different library you may need to convert the output.

Example

Original

Input Image
Input Image
import { texturePacker } from "@assetpack/core/texture-packer";

export default {
...
pipes: [
...
texturePacker({
texturePacker: {
padding: 2,
nameStyle: "relative",
removeFileExtension: false,
},
resolutionOptions: {
template: "@%%x",
resolutions: { default: 1, low: 0.5 },
fixedResolution: "default",
maximumTextureSize: 4096,
},
})
]
};

API

OptionTypeDescription
texturePackerobjectOptions for generating texture atlases.
texturePacker.textureFormatpng|jpgThe format of the texture atlas file.
Defaults to png.
texturePacker.paddingnumberThe padding between sprites in the texture atlas.
Defaults to 2.
texturePacker.fixedSizebooleanWhether the texture atlas should be a fixed size.
Defaults to false.
texturePacker.powerOfTwobooleanWhether the texture atlas should be a power of two.
Defaults to false.
texturePacker.widthnumberThe width of the texture atlas.
Defaults to 1024.
texturePacker.heightnumberThe height of the texture atlas.
Defaults to 1024.
texturePacker.allowTrimbooleanWhether the texture atlas should allow trimming.
Defaults to true.
texturePacker.allowRotationbooleanWhether the texture atlas should allow rotation.
Defaults to true.
texturePacker.alphaThresholdnumberThe alpha threshold for the texture atlas.
Defaults to 0.1.
texturePacker.scalenumberThe scale of the texture atlas.
Defaults to 1.
texturePacker.resolutionnumberThe resolution of the texture atlas.
Defaults to 1.
texturePacker.nameStyleshort|relativeThe name style of the texture atlas.
Defaults to relative.
texturePacker.removeFileExtensionbooleanWhether the file extension should be removed.
Defaults to false.
resolutionOptionsobjectOptions for generating resolutions.
resolutionOptions.templatestringA template for denoting the resolution of the images.
Defaults to @%%x.
resolutionOptions.resolutionsobjectAn object containing the resolutions that the images will be resized to.
Defaults to { default: 1, low: 0.5 }.
resolutionOptions.fixedResolutionstringA resolution used if the fix tag is applied. Resolution must match one found in resolutions.
Defaults to default.
resolutionOptions.maximumTextureSizenumberThe maximum size a sprite sheet can be before its split out.
Defaults to 4096.
addFrameNamesbooleanWhether to add frame names to the data in the manifest
Defaults to false.

Tags

TagFolder/FileDescription
tpsfolderIf present the folder will be processed by Texture Packer.
jpgfolderIf present the spritesheet will be saved as a jpg.
fixfolderIf present the spritesheet will be fixed to a specific resolution.

Texture Packer Compress

To compress the texture atlases you can use the texturePackerCompress plugin. This plugin uses the Sharp library to compress images into different formats, such as JPEG, PNG, WebP, and AVIF. This helps reduce file sizes while maintaining image quality, ensuring faster load times and better performance. This plugin also supports compressing images using the ASTC, ETC, ETC2, BCn (DXTn) and Basis supercompressed (ETC1S, UASTC) texture compression standard.

Example

Original

Input Image
Input Image
import { compress } from "@assetpack/core/image";
import { texturePackerCompress } from "@assetpack/core/texture-packer";

// these options are the default values, all options shown here are optional
const options = {
jpg: {},
png: { quality: 90 },
webp: { quality: 80, alphaQuality: 80, },
avif: false,
bc7: false,
astc: false,
basis: false,
};

export default {
...
pipes: [
...
compress(options),
texturePackerCompress(options),
]
};

API

See Compression API for more information.

You will want to make sure you are passing the same options to the compress plugin as you are to the texturePackerCompress plugin.

Tags

TagFolder/FileDescription
ncfolderIf present the atlas will not be compressed.