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
Maximum atlas width in pixels
Padding between sprites in pixels
Alternatively, pass an options object:
layerIds
ArrayLike<number>
required
Array of layer IDs to pack
Maximum atlas width in pixels
Padding between sprites in pixels
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
Maximum atlas width in pixels
Padding between sprites in pixels
Alternatively, pass an options object:
layerIds
ArrayLike<number>
required
Array of layer IDs to pack
Maximum atlas width in pixels
Padding between sprites in pixels
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
// }
Render a contact sheet grid from layers.
layerIds
ArrayLike<number>
required
Array of layer IDs
Number of columns in the grid
Padding between cells in pixels
background
ByteInput
default: "[0, 0, 0, 0]"
Background color as RGBA array
Alternatively, pass an options object:
layerIds
ArrayLike<number>
required
Array of layer IDs
Number of columns in the grid
Padding between cells in pixels
background
ByteInput
default: "[0, 0, 0, 0]"
Background color as RGBA array
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).
Integer scale factor (2x, 3x, etc.)
Alternatively, pass an options object:
comp . pixelScaleLayer ( layerId , 4 );
// or
comp . pixelScaleLayer ( layerId , { factor: 4 });
Color Quantization
Extract a color palette from a layer.
Maximum number of colors to extract
Alternatively, pass an options object:
Maximum number of colors to extract
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.
Flat RGBA palette data [r, g, b, a, r, g, b, a, …]
Alternatively, pass an options object:
// 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 });