Skip to main content

Sprite Sheet Packing

packSprites()

Pack layers into a sprite sheet atlas using shelf bin-packing.
layerIds
ArrayLike<number>
required
Array of layer IDs to pack
maxWidth
number
required
Maximum atlas width in pixels
padding
number
default:"0"
Padding between sprites in pixels
Alternatively, pass an options object:
options
PackSpritesOptions
rgba
Uint8Array
Raw RGBA pixel data of the packed sprite sheet
const layerIds = [1, 2, 3, 4, 5];
const atlasData = comp.packSprites(layerIds, 512, 2);
// or
const atlasData = comp.packSprites({
  layerIds: layerIds,
  maxWidth: 512,
  padding: 2
});

packSpritesJson()

Pack layers into a sprite sheet and return JSON metadata.
layerIds
ArrayLike<number>
required
Array of layer IDs to pack
maxWidth
number
required
Maximum atlas width in pixels
padding
number
default:"0"
Padding between sprites in pixels
Alternatively, pass an options object:
options
PackSpritesOptions
json
string
JSON string with sprite positions and atlas dimensions
const metadata = comp.packSpritesJson(layerIds, 512, 2);
const data = JSON.parse(metadata);
// data = {
//   sprites: [
//     { index: 0, x: 0, y: 0, w: 64, h: 64 },
//     { index: 1, x: 66, y: 0, w: 32, h: 32 },
//     ...
//   ],
//   width: 512,
//   height: 256
// }

Contact Sheets

contactSheet()

Render a contact sheet grid from layers.
layerIds
ArrayLike<number>
required
Array of layer IDs
columns
number
required
Number of columns in the grid
padding
number
default:"0"
Padding between cells in pixels
background
ByteInput
default:"[0, 0, 0, 0]"
Background color as RGBA array
Alternatively, pass an options object:
options
ContactSheetOptions
rgba
Uint8Array
Raw RGBA pixel data of the contact sheet
const frameIds = [1, 2, 3, 4, 5, 6];
const sheet = comp.contactSheet(frameIds, 3, 4, [255, 255, 255, 255]);
// or
const sheet = comp.contactSheet({
  layerIds: frameIds,
  columns: 3,
  padding: 4,
  background: [255, 255, 255, 255]
});
Cell dimensions are automatically derived from the largest layer.

Pixel Art Utilities

pixelScaleLayer()

Scale a layer by an integer factor using nearest-neighbor interpolation (ideal for pixel art).
id
number
required
Layer ID
factor
number
required
Integer scale factor (2x, 3x, etc.)
Alternatively, pass an options object:
options
PixelScaleOptions
comp.pixelScaleLayer(layerId, 4);
// or
comp.pixelScaleLayer(layerId, { factor: 4 });

Color Quantization

extractPalette()

Extract a color palette from a layer.
id
number
required
Layer ID
maxColors
number
required
Maximum number of colors to extract
Alternatively, pass an options object:
options
PaletteOptions
palette
Uint8Array
Flat RGBA palette data [r, g, b, a, r, g, b, a, …]
const palette = comp.extractPalette(layerId, 16);
// or
const palette = comp.extractPalette(layerId, { maxColors: 16 });

quantizeLayer()

Quantize a layer to a specific color palette.
id
number
required
Layer ID
palette
ByteInput
required
Flat RGBA palette data [r, g, b, a, r, g, b, a, …]
Alternatively, pass an options object:
options
QuantizeOptions
// Extract palette from one layer
const palette = comp.extractPalette(sourceId, 16);

// Apply it to another layer
comp.quantizeLayer(targetId, palette);
// or
comp.quantizeLayer(targetId, { palette });

Build docs developers (and LLMs) love