All examples · Audio

Sound and spatial audio

What this example shows

useLoadAudio loads a clip like a texture and useSound hands back the controls. A one-off effect sounds on top of itself; a looping one is a single sound you pause and resume. Each one belongs to a channel, and useAudio moves those volumes: the sliders of an options screen. Click a coin (the first click is also what lets the browser make noise), M toggles the ambience, and the arrows move the music volume.

The bird carries a spatial: true sound, so it crosses from one ear to the other and fades with distance, measured in pixels from the middle of what the camera shows. P pauses the level: the engine never silences anything by itself, it only says so with scenePaused, and this example stops the birds while the ambience carries on.

Starting