AudioAsset
audio/audio-asset.ts:40 Extends Asset
An Asset wrapping a decoded audio clip as a Web Audio
AudioBuffer.
AudioAsset is what AssetLibrary.load produces for any path that
resolves to AssetType.Audio — MP3, Ogg Vorbis, WAV, M4A/AAC, FLAC,
WebM/Opus. It is the handoff between the asset layer and the audio
playback layer: the audio-playing components (AudioSource,
Music) take an AudioAsset and pull the decoded buffer from it
internally, so game code references sounds by key and never touches an
AudioBuffer itself.
The browser AudioBuffer is deliberately not part of arcade2d's stable
surface — it is reachable only through AudioAsset.raw, the escape
hatch. The duration a sequencing-minded caller actually needs is surfaced
as a plain number via AudioAsset.duration.
Decoding cost
Decoding happens during AssetLibrary.load — the moment the load promise resolves, the clip is decoded, in memory, and ready to play with no audible latency at the first play. This is what makes audio behave like any other arcade2d asset: preload it eagerly at a coarse boundary, then play it any number of times for free.
Example
await game.assets.load('sfx/explosion.wav', { key: 'explosion' });
const explosion = game.assets.getAs('explosion', AudioAsset);
console.log(explosion.duration);Constructors
constructor(key: string, namespace: string, src: string, _buffer: AudioBuffer): AudioAsset Parameters
-
keystring -
namespacestring -
srcstring -
_bufferAudioBuffer
Properties
key: string The developer-facing name this asset is stored under within its Asset.namespace. Unique per namespace, not globally.
namespace: string The grouping this asset belongs to. The unit of bulk unloading via AssetLibrary.unloadNamespace.
src: string The resolved path the resource was loaded from. Also the underlying renderer's cache key, used to free the resource on unload.
Accessors
channelCount: number The number of audio channels in the underlying buffer (1 for mono,
2 for stereo).
raw: AudioBuffer Direct access to the underlying Web Audio AudioBuffer instance.
Use with care. raw is an intentional escape hatch for cases the
arcade2d API doesn't cover — feeding the buffer into a custom audio
graph, sampling its PCM data, anything we haven't decided how to model
yet. Code that touches raw is coupled to the Web Audio API and may
break when arcade2d swaps the audio backend.
None of those will be treated as breaking changes to arcade2d's own
surface. Prefer the typed accessors on this class; reach for raw only
when no equivalent exists, and isolate the access behind your own helper
so the coupling is in one place.