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.
Properties
Section titled “Properties”context
Section titled “context”context:
AudioContext
musicVolume
Section titled “musicVolume”musicVolume:
number
Volume of the music channel, 0–1: playMusic, and play with music: true.
soundVolume
Section titled “soundVolume”soundVolume:
number
Volume of the sound channel, 0–1: every other play.
volume
Section titled “volume”volume:
number
Master volume, 0–1.
Methods
Section titled “Methods”loadSound()
Section titled “loadSound()”loadSound(
url):Promise<AudioBuffer>
Loads and decodes one sound. Cached by URL.
Parameters
Section titled “Parameters”string
Returns
Section titled “Returns”Promise<AudioBuffer>
loadSounds()
Section titled “loadSounds()”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.
Type Parameters
Section titled “Type Parameters”M extends Record<string, string>
Parameters
Section titled “Parameters”manifest
Section titled “manifest”M
Returns
Section titled “Returns”Promise<{ [K in string | number | symbol]: AudioBuffer }>
play()
Section titled “play()”play(
sound,options?): () =>void
Plays a loaded sound and returns a function that stops it.
Parameters
Section titled “Parameters”AudioBuffer
options?
Section titled “options?”Returns
Section titled “Returns”() => void
playMusic()
Section titled “playMusic()”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.
Parameters
Section titled “Parameters”string
options?
Section titled “options?”Returns
Section titled “Returns”() => void
