AssetManager
Defined in: AssetManager.ts:27
Orchestrates asset loading across plugin-provided loaders. Core owns the “when” and “what”; plugins own the “how”.
Loads are reference-counted by type:path: every handle passed to
loadAll adds a reference once the whole call has resolved, and unload
only fires the loader’s unload once the last reference is released.
Without this, two scenes preloading the same asset share one cache
entry, so the first unload would tear the asset out from under the other —
the underlying Pixi Assets/BitmapFont registries dedupe by key and are
not ref-counted, so the destruction would be real. clear ignores the
counts and frees everything outright.
A failed loadAll takes no references at all, so its already-loaded
siblings stay cached and uncounted: a retry counts each of them once and a
single unload per handle frees them.
Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new AssetManager():
AssetManager
Returns
Section titled “Returns”AssetManager
Methods
Section titled “Methods”clear()
Section titled “clear()”clear():
void|Promise<void>
Defined in: AssetManager.ts:147
Unload every cached asset outright, ignoring reference counts.
Returns
Section titled “Returns”void | Promise<void>
get<
T>(handle):T
Defined in: AssetManager.ts:43
Retrieve a loaded asset. Throws if not loaded.
Type Parameters
Section titled “Type Parameters”T
Parameters
Section titled “Parameters”handle
Section titled “handle”AssetHandle<T>
Returns
Section titled “Returns”T
has(
handle):boolean
Defined in: AssetManager.ts:55
Check if an asset is loaded.
Parameters
Section titled “Parameters”handle
Section titled “handle”AssetHandle<unknown>
Returns
Section titled “Returns”boolean
loadAll()
Section titled “loadAll()”loadAll(
handles,onProgress?):Promise<void>
Defined in: AssetManager.ts:78
Load all assets, adding a reference to each and loading only the ones not already cached. Reports progress via optional callback (0→1).
Every distinct handle in handles adds one reference — whether it was
freshly loaded or already cached — once every load in the call has
resolved, so two scenes preloading the same asset each hold a reference
and a single unload won’t free it under the other. Duplicate handles
within one call count once, and a call that rejects counts nothing.
A loader that loads assets of its own — a Tiled map loads its tileset
images — holds one reference on each of them for as long as its own
entry is cached, and freeing that entry releases them. A map cached by a
call that then rejected still owns its images: the unload that follows
a retry frees both, and so does one unload of the uncounted map.
A second handle for a path already loaded under a different data reuses
the first load and warns: the cache is keyed by type and path alone.
Parameters
Section titled “Parameters”handles
Section titled “handles”readonly AssetHandle<unknown>[]
onProgress?
Section titled “onProgress?”(ratio) => void
Returns
Section titled “Returns”Promise<void>
registerLoader()
Section titled “registerLoader()”registerLoader(
type,loader):void
Defined in: AssetManager.ts:38
Register a loader for a given asset type. Called by plugins during install().
Parameters
Section titled “Parameters”string
loader
Section titled “loader”Returns
Section titled “Returns”void
unload()
Section titled “unload()”unload(
handle):void|Promise<void>
Defined in: AssetManager.ts:126
Release one reference to an asset. The loader’s unload runs and the cache
entry is dropped only when the last reference is released; earlier calls
just decrement. An entry left uncounted by a loadAll that rejected is
freed by its first unload. A no-op for handles that were never loaded.
Returns the loader’s completion when cleanup is asynchronous. The cache
entry is removed immediately; a new load waits for cleanup to complete.
Failed cleanup rejects and prevents reloading that path.
Parameters
Section titled “Parameters”handle
Section titled “handle”AssetHandle<unknown>
Returns
Section titled “Returns”void | Promise<void>
Coding agents: fetch https://yage.dev/llms.txt first and prefer the Markdown references it links over these HTML pages. This page's Markdown counterpart is /llms/packages/core.md.