Skip to content

Audio

Web Audio playback: game.get(Audio) after adding the audio() plugin. Two channels, sounds and music, each with its own volume under the master volume, so a settings menu can turn the music down and keep the effects.

context: AudioContext


musicVolume: number

Volume of the music channel, 0–1: playMusic, and play with music: true.


soundVolume: number

Volume of the sound channel, 0–1: every other play.


volume: number

Master volume, 0–1.

loadSound(url): Promise<AudioBuffer>

Loads and decodes one sound. Cached by URL.

string

Promise<AudioBuffer>


loadSounds<M>(manifest): Promise<{ [K in string | number | symbol]: AudioBuffer }>

Loads and decodes sounds in parallel: const s = await audio.loadSounds({ jump: jumpUrl }) gives a typed s.jump.

M extends Record<string, string>

M

Promise<{ [K in string | number | symbol]: AudioBuffer }>


play(sound, options?): () => void

Plays a loaded sound and returns a function that stops it.

AudioBuffer

PlayOptions

() => void


playMusic(url, options?): () => void

Streams a long track (music, ambience) from a URL on the music channel, without decoding all of it into memory first, and returns a function that stops it. Loops by default.

string

MusicOptions

() => void