Skip to content
Work in progress. These docs describe Spawnite at launch, and some parts are still being built.

Sound

<Sound url> plays a sound file inside a World from when it mounts until the file ends or the component unmounts. Where you mount it decides where the player hears it from:

  • Inside an Entity, the sound comes from the entity and grows quieter with distance from the camera.
  • Anywhere else, the player hears it the same everywhere: an ambience, or a sting at the end of a round.

Its props are in SoundProps.

Roblox’s Sound works the same way: parented to a part it plays from there, and parented anywhere else it plays everywhere. Unity’s AudioSource and Godot’s AudioStreamPlayer3D are the placed kind; Godot’s AudioStreamPlayer is the everywhere kind.

A browser, a phone’s included, keeps a page silent until the player presses a key, clicks or touches the screen. A Sound mounted before that input starts playing on it. A one-off sound that a pickup or a footstep plays before that input does not play.

An iPhone with its ring switch set to silent plays no page sound, a game’s included, until the player sets it back to ring.

A browser with no Web Audio, or one that cannot start it, runs the game silent rather than stopping it. Sound mounts nothing, and footsteps and pickups play nothing. The console says so once: Web Audio is unavailable in this browser, so the game runs silent, followed by the browser’s own error. The game needs no change. Other players’ voices still play, through an audio element, up to 100% volume, as voice says.

Two sounds need no Sound of their own:

  • <CharacterSpawn footsteps> takes a list of files and plays one of them at random for each stride she walks. A stride is 1.67 metres, a third of her top speed of 5 m/s, which matches the three steps a second of her run.
  • <Pickup sound> plays its file once, heard everywhere, as she takes the pickup. It does not play when the scene ends around a pickup nobody took.

sounds names the files in the shared asset library, which ship with the engine, and says what each one is for. Assets says where to find more, and how to check a downloaded sound for hiss.

import {
CharacterSpawn,
Entity,
Pickup,
Sound,
sounds,
World,
} from "@spawnite/engine";
export function Run() {
return (
<World map="meadow">
<CharacterSpawn />
<Sound url="/sounds/rain.mp3" loop volume={0.5} />
<Entity position={[0, 0, -3]}>
<Pickup reward={1} sound={sounds.pickup} />
</Entity>
</World>
);
}

Client. Sound changes nothing in the world; each player hears their own. Removing a game’s frame frees its audio with everything else it held, as the trust boundary says.