Skip to content

Atlas

Pages of baked art. bake() draws into a scratch canvas, copies it into a page and queues the upload.

new Atlas(pageSize?, maxPages?): Atlas

Pages of pageSize × pageSize pixels, at most maxPages before a wipe.

number

A page’s side, pixels.

number

Pages kept before the atlas is wiped.

Atlas

readonly pageSize: number

A page’s side, pixels.


readonly maxPages: number

Pages kept before the atlas is wiped.


readonly pages: object[]

The pages, each a canvas with its packer.

surface: Surface

packer: ShelfPacker

ctx: CanvasRenderingContext2D


gen: number

The generation: bumped when the atlas is wiped (frames of an older one are baked again).


onPage: (s) => void

Called when a page is added (the engine keeps track of surfaces).

Surface

void


onDrop: (s) => void

Called when a page is dropped by a wipe: free its GPU texture (renderer.destroyTexture).

Surface

void

valid(f): f is Frame

Whether a frame is still in the atlas (not wiped by a reset).

Frame | null | undefined

f is Frame


bake(w, h, draw, scale?, ox?, oy?, margin?): Frame

A w × h region (pixels) drawn by draw(ctx) with (0, 0) at its top-left: a frame of it. A new page is made while there are fewer than maxPages, or for an item bigger than a page (a page of its own, its size). When every page is full the atlas is wiped (gen changes, every frame is baked again on its next use): the first maxPages pages of the usual size are kept, emptied, the others dropped, and the item goes on the first page.

number

number

(ctx) => void

number

number

number

number

Frame


add(source, scale?, ox?, oy?): Frame

An image or canvas put into the atlas as it is.

CanvasImageSource & object

number

number

number

Frame


release(f): void

Gives a frame’s place back (texts that changed size).

Frame

void


rebake(f, w, h, draw, maxW?, maxH?): Frame | null

Bakes again into the same place, if the new size fits in it (texts that change): the frame, updated, or null (bake a new one).

Frame

number

number

(ctx) => void

number

number

Frame | null


wipe(): void

Every page emptied: frames of the old generation are baked again when used. Pages past maxPages, and pages made bigger for one big item, are dropped (onDrop frees their textures).

void