Sound
An audio clip a sprite or the stage can play, such as a pop or a music loop. Sounds can be started and left to finish, played to completion, or shaped with effects like pitch and pan.
The Sound engine class. Most members are available as free functions; this page documents the underlying API for advanced use.
audioContext
Section titled “audioContext”Sound.audioContext: AudioContextThe shared Web Audio context that all sounds play through, created on first use.
Since 1.0.0
connect
Section titled “connect”Sound.connect(target: AudioNode): voidRoutes the sound’s audio output into the given audio node (such as an effect chain).
Since 1.0.0
downloadMyAudioBuffer
Section titled “downloadMyAudioBuffer”Sound.downloadMyAudioBuffer(): Promise<AudioBuffer | null>Downloads and decodes the sound’s audio data so it is ready to play.
Since 1.0.0
duration
Section titled “duration”Sound.duration: numberHow long the sound lasts, in seconds (0 until the audio has downloaded).
Since 1.0.0
isConnectedTo
Section titled “isConnectedTo”Sound.isConnectedTo(target: AudioNode): booleanChecks whether the sound is currently routed to the given audio node.
Since 1.0.0
Sound.name: stringThe name used to refer to this sound, as shown in the sound list.
Since 1.0.0
playUntilDone
Section titled “playUntilDone”Sound.playUntilDone(): Yielding<void>Plays the sound and waits until it has completely finished playing.
This is a Yielding generator that pauses until the sound finishes, so
engine code awaits it with yield*.
Pauses the script (a generator). In sprite code the free-function wrapper awaits it for you.
Since 1.0.0
Example
yield* this.mySound.playUntilDone();setPlaybackRate
Section titled “setPlaybackRate”Sound.setPlaybackRate(value: number): voidChanges how fast the sound plays, which also changes its pitch.
Since 1.0.0
Sound.start(): Yielding<boolean>Begins playing the sound and returns once it has actually started.
This is a Yielding generator that pauses until the sound has begun
playing, so engine code awaits it with yield*.
Pauses the script (a generator). In sprite code the free-function wrapper awaits it for you.
Since 1.0.0
Example
yield* this.mySound.start();Sound.stop(): voidImmediately stops the sound if it is currently playing.
Since 1.0.0
Sound.url: stringThe location the sound’s audio data is downloaded from.
Since 1.0.0