Atlas
Named regions packed onto texture pages.
ts
import { Atlas, PackerConfig, AtlasEntry } from "willow";Atlas
ts
class AtlasA 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
| Member | Description |
|---|---|
has(name: string): boolean | True if a region named name has been packed/parsed into this atlas. |
region(name: string): TextureRegion | The 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): TextureRegion | Packs 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): void | Buffers 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(): void | Packs every staged image (MaxRects). Batch atlases only, and only once, a second call raises. |
regionCount(): int | Number of named regions currently packed/parsed into this atlas. |
dispose(): void | Releases the atlas's packer/page state. Idempotent, like every other dispose(). |
Atlas: static methods
| Member | Description |
|---|---|
static load(jsonText: string, texture: Texture): Atlas | Parses a TexturePacker JSON manifest against an existing page texture. |
static loadIntoScene(jsonText: string, texture: Texture): Atlas | |
static create(config?: PackerConfig): Atlas | Creates an empty atlas for dynamic packing via add. |
static createBatch(config?: PackerConfig): Atlas | Creates an empty atlas for batch packing via stage/pack. |
PackerConfig
ts
class PackerConfigPage-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
| Member | Description |
|---|---|
pageWidth: int | Atlas page width in pixels. Defaults to 2048 when unset. |
pageHeight: int | Atlas page height in pixels. Defaults to 2048 when unset. |
padding: int | Pixel gap between packed images. Defaults to 1 when unset. |
AtlasEntry
ts
class AtlasEntryOne 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
| Member | Description |
|---|---|
style: string | Font style this atlas page was baked for ("regular" | "bold" | "italic" | "boldItalic"). |
bakeSize: float | SDF/bitmap bake size, in pixels, this page was baked at. |
png: Buffer | Raw PNG bytes for the atlas page image. |
json: Buffer | Raw JSON bytes for the atlas page's glyph manifest. |