Skip to content

Atlas ​

Named regions packed onto texture pages.

ts
import { Atlas, PackerConfig, AtlasEntry } from "willow";

Atlas ​

ts
class Atlas

A named collection of texture regions. Built one of three ways:

, Atlas.load / Atlas.loadIntoScene parse an existing TexturePacker JSON manifest against an already-loaded page Texture. , Atlas.create packs images in dynamically, one at a time, via add. , Atlas.createBatch stages images upfront via stage, then packs them all at once via pack for tighter results.

Atlas: methods ​

MemberDescription
has(name: string): booleanTrue if a region named name has been packed/parsed into this atlas.
region(name: string): TextureRegionThe region named name, or a 1x1 magenta placeholder if missing. Raises on a batch atlas that has not been packed yet.
add(name: string, width: int, height: int, rgba: Buffer | Uint8Array): TextureRegionPacks width * height * 4 RGBA bytes into the atlas under name and returns its region. Dynamic atlases only (from Atlas.create) and requires an initialized renderer. It is therefore unavailable in a headless console program.
stage(name: string, width: int, height: int, rgba: Buffer | Uint8Array): voidBuffers width * height * 4 RGBA bytes under name for later packing via pack. Batch atlases only (from Atlas.createBatch, before pack has run), raises otherwise, including on a duplicate name.
pack(): voidPacks every staged image (MaxRects). Batch atlases only, and only once, a second call raises.
regionCount(): intNumber of named regions currently packed/parsed into this atlas.
dispose(): voidReleases the atlas's packer/page state. Idempotent, like every other dispose().

Atlas: static methods ​

MemberDescription
static load(jsonText: string, texture: Texture): AtlasParses a TexturePacker JSON manifest against an existing page texture.
static loadIntoScene(jsonText: string, texture: Texture): Atlas
static create(config?: PackerConfig): AtlasCreates an empty atlas for dynamic packing via add.
static createBatch(config?: PackerConfig): AtlasCreates an empty atlas for batch packing via stage/pack.

PackerConfig ​

ts
class PackerConfig

Page-size and padding configuration for a dynamically-packed atlas. All three fields are optional; unset fields default the same way Atlas.create/Atlas.createBatch do without a config at all: 2048x2048 pages, 1 pixel padding.

PackerConfig: constructors ​

ts
new PackerConfig(pageWidth?: int, pageHeight?: int, padding?: int)

PackerConfig: properties ​

MemberDescription
pageWidth: intAtlas page width in pixels. Defaults to 2048 when unset.
pageHeight: intAtlas page height in pixels. Defaults to 2048 when unset.
padding: intPixel gap between packed images. Defaults to 1 when unset.

AtlasEntry ​

ts
class AtlasEntry

One baked font-atlas page: a style/size tag plus the raw PNG and JSON bytes TexturePacker-style tooling exchanges for it.

AtlasEntry: constructors ​

ts
new AtlasEntry(style: string, bakeSize: float, png: Buffer, json: Buffer)

AtlasEntry: properties ​

MemberDescription
style: stringFont style this atlas page was baked for ("regular" | "bold" | "italic" | "boldItalic").
bakeSize: floatSDF/bitmap bake size, in pixels, this page was baked at.
png: BufferRaw PNG bytes for the atlas page image.
json: BufferRaw JSON bytes for the atlas page's glyph manifest.