Atlas
Pages of baked art. bake() draws into a scratch canvas, copies it into a page and queues the upload.
Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new Atlas(
pageSize?,maxPages?):Atlas
Pages of pageSize × pageSize pixels, at most maxPages before a wipe.
Parameters
Section titled “Parameters”pageSize?
Section titled “pageSize?”number
A page’s side, pixels.
maxPages?
Section titled “maxPages?”number
Pages kept before the atlas is wiped.
Returns
Section titled “Returns”Atlas
Properties
Section titled “Properties”pageSize
Section titled “pageSize”
readonlypageSize:number
A page’s side, pixels.
maxPages
Section titled “maxPages”
readonlymaxPages:number
Pages kept before the atlas is wiped.
readonlypages:object[]
The pages, each a canvas with its packer.
surface
Section titled “surface”surface:
Surface
packer
Section titled “packer”packer:
ShelfPacker
ctx:
CanvasRenderingContext2D
gen:
number
The generation: bumped when the atlas is wiped (frames of an older one are baked again).
onPage
Section titled “onPage”onPage: (
s) =>void
Called when a page is added (the engine keeps track of surfaces).
Parameters
Section titled “Parameters”Returns
Section titled “Returns”void
onDrop
Section titled “onDrop”onDrop: (
s) =>void
Called when a page is dropped by a wipe: free its GPU texture (renderer.destroyTexture).
Parameters
Section titled “Parameters”Returns
Section titled “Returns”void
Methods
Section titled “Methods”valid()
Section titled “valid()”valid(
f):f is Frame
Whether a frame is still in the atlas (not wiped by a reset).
Parameters
Section titled “Parameters”Frame | null | undefined
Returns
Section titled “Returns”f is Frame
bake()
Section titled “bake()”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.
Parameters
Section titled “Parameters”number
number
(ctx) => void
scale?
Section titled “scale?”number
number
number
margin?
Section titled “margin?”number
Returns
Section titled “Returns”add(
source,scale?,ox?,oy?):Frame
An image or canvas put into the atlas as it is.
Parameters
Section titled “Parameters”source
Section titled “source”CanvasImageSource & object
scale?
Section titled “scale?”number
number
number
Returns
Section titled “Returns”release()
Section titled “release()”release(
f):void
Gives a frame’s place back (texts that changed size).
Parameters
Section titled “Parameters”Returns
Section titled “Returns”void
rebake()
Section titled “rebake()”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).
Parameters
Section titled “Parameters”number
number
(ctx) => void
number
number
Returns
Section titled “Returns”Frame | null
wipe()
Section titled “wipe()”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).
Returns
Section titled “Returns”void