AURA

JSGG

AuraJS
DOCSEXAMPLESGITHUB
04 Assets, Audio, Persistence, and Runtime FS
Asset loading, audio playback, persistence, and runtime filesystem helpers.
docs/external/game-dev-api/04-assets-audio-and-persistence.md

Assets, Audio, Persistence, and Runtime FS

This page covers loading content, audio playback, simple save persistence, and the runtime file API.

`aura.assets`

Core loading surface:

  • load(path)
  • exists(path)
  • loadJson(path)
  • loadText(path)
  • loadFont(path)
  • loadBitmapFont(path)
  • getFormatSupport(path)

Streaming/cache helpers:

  • getState(path)
  • getStateHistory(path)
  • evict(path)
  • getCachePolicy()
  • setCachePolicy(policy)
  • preload2d(paths)
  • preload3d(paths)

Use cases:

  • deterministic asset preloading
  • text/json/font ingestion
  • cache lifecycle introspection for large projects

Notes:

  • The canonical game-dev surface is the load* family above.
  • Some shims/test harnesses expose convenience getters, but the contract-backed API is load, loadJson, loadText, and the preload/cache methods listed here.

`aura.audio`

Core playback and global control:

  • play(...)
  • stop(handle)
  • pause(handle)
  • resume(handle)
  • getState(handle)
  • setVolume(handle, volume)
  • setMasterVolume(volume)
  • pauseAll()
  • resumeAll()
  • stopAll()

Spatial audio and listener/emitter helpers:

  • setHRTF(enabled)
  • setListener(options)
  • playSpatial(pathOrSpec, options)
  • setEmitterPosition(handle, position)
  • setOcclusion(handle, value)
  • addReverbZone(zone)
  • removeReverbZone(zoneId)
  • clearReverbZones()

Mixer/bus/envelope helpers:

  • setBusVolume(bus, volume)
  • assignBus(handle, bus)
  • fadeTrack(handle, options)
  • fadeBus(bus, options)
  • crossfade(fromHandle, toHandle, options)
  • update(dt)
  • clearEnvelopes()
  • getMixerState()

Use cases:

  • SFX/music routing
  • spatial emitters attached to world objects
  • dynamic bus control and cinematic crossfades
  • explicit pause-menu and cutscene audio ownership
  • live handle-state checks without bespoke per-game registries

Truth boundary:

  • getState(handle) returns null for unknown or inactive handles
  • mixer-backed voices expose live playback state, volume/pitch, and timing fields
  • resumeAll() only resumes handles paused by pauseAll(), not handles gameplay paused explicitly earlier
  • external fallback playback still reports active/paused/volume truth, but timing fields stay null because that runtime path does not own sample position

Scaffolded 2D Scene Audio Helper

Generated 2D projects can also use src/starter-utils/scene-audio-2d.js when you want one explicit scene-level ownership lane on top of aura.audio.

The helper owns a deliberately small contract:

  • createSceneAudio2D(aura, options?)
  • ensureSceneMusic2D(sceneAudio, path, options?)
  • playSceneStinger2D(sceneAudio, path, options?)
  • pauseSceneAudio2D(sceneAudio, options?)
  • resumeSceneAudio2D(sceneAudio, options?)
  • syncSceneAudio2D(sceneAudio, dt, options?)
  • stopSceneAudio2D(sceneAudio, options?)

Truth boundary:

  • it is a shared music/stinger/duck/pause/resume helper for medium 2D games
  • it still runs on the existing aura.audio mixer/bus surface
  • it does not claim audio middleware, authoring tools, or packaged asset resolution beyond the paths you provide
  • the accepted packaged/native path is a project-relative asset path such as assets/title-loop.wav
  • when you need explicit runtime gating before playback, probe the path with aura.assets.exists(path) first

`aura.storage`

Persistence surface:

  • save(key, value)
  • load(key, fallback?)
  • delete(key)
  • keys()

Legacy aliases:

  • set(key, value)
  • get(key, fallback?)

Use cases:

  • simple preferences
  • small save metadata
  • local high scores and unlocked flags

For larger authored 2D worlds, the scaffolded helper lane now includes world-persistence-2d.js for explicit streamed-world snapshot and rehydrate ownership over aura.storage.

Keep that boundary honest:

  • it captures only the region/world adapters you provide
  • it is a continuity helper for fresh-run restore, not a universal mid-frame save-state system
  • off-screen simulation and richer object continuity remain downstream of the first persistence slice

`aura.fs`

Runtime-safe file helpers:

  • exists(path)
  • readText(path)
  • writeText(path, value)
  • readJson(path)
  • writeJson(path, value)
  • mkdir(path)
  • list(path)
  • remove(path)

Important notes:

  • paths are validated to stay inside the runtime/project root
  • absolute paths and .. traversal are rejected
  • this is useful for runtime notes, exported data, local tools, and generated content

For richer save/export/apply flows, see 07 Scenes, State, Debug, and Test Harness and the auramaxx state CLI docs.

DOCUMENT REFERENCE
docs/external/game-dev-api/04-assets-audio-and-persistence.md
AURAJS
Cmd/Ctrl+K
aurajsgg