Fraxel’s asset pipeline is built around a symbol-based ID system: every loaded asset is identified by a uniqueDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/sanchedev/fraxel/llms.txt
Use this file to discover all available pages before exploring further.
symbol returned at load time. This means you never pass raw URLs into nodes — you pass the stable symbol your loader gave you. All loaders are fully async and integrate naturally with top-level await in ES modules or inside any async function.
Loading Textures
loadTexture(url) loads an image from a URL, stores it in the internal texture registry, and returns a Promise<symbol> ID. Pass that symbol to any <sprite> via its textureId prop.
loadTexture creates an HTMLImageElement, waits for its load event, then wraps it in a Texture instance stored in a Map<symbol, Texture>. On the next call with the same URL, the map is scanned and the existing symbol is returned immediately — no network round-trip.
Texture URLs are deduplicated automatically. If two modules both call
loadTexture('/assets/player.png'), they receive the same symbol and share the same underlying HTMLImageElement. Note that loadSound does not deduplicate — each call returns a new symbol and issues a fresh network request.Loading Sounds
loadSound(url) fetches an audio file, decodes it through the Web Audio AudioContext, and returns a Promise<symbol> ID. The decoded AudioBuffer is stored in a module-level Map<symbol, AudioBuffer> and can be played back through the <audio-player> node.
AudioContext.decodeAudioData, playback is instant with no stutter. See Audio for how to trigger sounds with <audio-player>.
Batch Loading
When you need to load many assets before entering a scene,loadBatch fires all loaders in parallel via Promise.all and calls an optional onProgress callback after each individual asset resolves — perfect for driving a loading bar.
Function Reference
| Function | Signature | Description |
|---|---|---|
loadTexture | (url: string) => Promise<symbol> | Loads an image; returns a deduplicated symbol ID |
loadSound | (url: string) => Promise<symbol> | Loads and decodes an audio buffer; returns a new symbol ID each call |
loadBatch | (loaders: (() => Promise<T>)[], options?: LoaderOptions) => Promise<T[]> | Loads multiple assets in parallel with progress tracking |
loadBatchAsset | (type: AssetType, urls: string[], options?: LoaderOptions) => Promise<symbol[]> | Typed variant for loading multiple same-type assets |
unloadTexture | (id: symbol) => void | Removes a texture from memory |
unloadSound | (id: symbol) => void | Removes a sound buffer from memory |
LoaderOptions
| Property | Type | Description |
|---|---|---|
onProgress | (loaded: number, total: number) => void | Invoked after each asset resolves; loaded counts completed assets, total is the batch size |
loadBatchAsset
loadBatchAsset is a convenience wrapper over loadBatch for when all assets in a batch share the same type. It accepts a type string ('texture' or 'sound'), an array of URLs, and optional LoaderOptions. The return type is always Promise<symbol[]>.
onProgress as a third argument:
Unloading Assets
When assets are no longer needed — after leaving a scene, for example — free their memory withunloadTexture or unloadSound. The symbol ID becomes invalid after unloading; do not pass it to nodes afterwards.
Map.delete(id) on the respective registry, allowing the garbage collector to reclaim the underlying HTMLImageElement or AudioBuffer.
Usage Patterns
Pattern 1 — Individual Loading at Module Top Level
For small games or prototypes, load assets at the top of each module withawait. Because ES modules support top-level await, the imported symbol is ready before any component that imports the module runs.
Pattern 2 — Batch Loading with Progress Bar
Centralise all asset loading in apreload function and call it before mounting your scene. This lets you show a loading screen while assets stream in.
Pattern 3 — Per-Scene Loading with loadBatchAsset
For larger games with multiple levels, load only the assets that belong to the current scene and unload them when leaving. loadBatchAsset keeps this concise when all assets share a type.
Related pages: Nodes 2D · Hooks · Audio · Filters · API: Assets