Skip to content

Sounds ​

What the game and its interface sound like: sounds by name, played on buses the player sets the volume of. The interface's own clicks and the menu's open and close sounds are yours to give; with none, it is silent.

Quick start ​

ts
// the app's screens: files by address
startApp({ target: '#game', scenes, sounds: { press: '/ui/click.ogg', open: '/ui/open.ogg' } })

// the game's view: sounds by name (files in public/sounds, or your game's own folder)
export const view: GameView = {
	units: { looks: {} },
	hud: { sounds: { press: 'click', open: 'menuOpen', close: 'menuClose' } },
	sounds: { ambience: 'wind', hearing: { mode: 'hrtf' } }
}

Menus click, the pause menu sounds as it opens and closes, wind loops behind the game, and sounds are placed around the player's head.

Common tasks ​

Play a sound from your view ​

ts
client.sounds.play('chime', { x: 40, z: 60 }, 0.8) // name, where, volume (then delay, bus)
client.sounds.loop('rain') // a loop of your own

In a component of yours, useUiSound()('press') plays an interface sound where it is.

Decide a sound in code ​

ts
sounds: {
	soundFor: (event, { entity, state, cinematic }) => (event === 'death' && entity?.def.id === 'lich' ? 'lichScream' : undefined)
}

Return a name, { sound, at, volume }, null for silence, or nothing for the default. Voice.respond({ entity, kind, order, repeats }) decides what a unit says when picked or ordered.

Start sooner by loading fewer sounds ​

ts
sounds: { preload: ['click', 'error', 'victory', 'defeat'] } // the rest load behind the game

A sound heard before its file arrives plays as it comes, up to sounds.late seconds late (0.25), or not at all.

Give your game's sounds and models a folder of its own ​

ts
files: { assets: 'games/campaign' } // under public: sounds/, models/, sounds/music/, with an assets.json
json
{ "sounds": { "chime": 1, "rattle": 3 }, "models": ["units/lich.glb"], "music": ["theme"] }

The number is how many takes (rattle_1.mp3, rattle_2.mp3…). What it lists comes from there; everything else from the shared public/sounds and public/models. See How do I add sounds and music.

Reference ​

Buses ​

Every sound plays on a bus: effects, voice, music, ambience, interface. The player sets each in the mixer (Settings › volume). Music and ambience duck while anyone speaks.

Interface sounds (UiSounds) ​

open, close, hover, press. The app's screens take files by address (startApp({ sounds })), played on the interface bus; the HUD takes your game's sounds by name (GameView.hud.sounds): the pause menu opening and closing, its lines and the end screen's buttons hovered and pressed.

GameView.sounds ​

FieldWhat
by namewhat each sound is (files in public/sounds or your folder)
ambiencea loop behind the game
hearinghow far sounds carry; mode: 'stereo' (default) or 'hrtf'
preloadwhich load before the game (a list, or a function of a name); all the view names by default
latehow late a sound may start once its file arrives (0.25 s)
soundFordecide an event's sound in code
chargedby ability id, how it sounds charged

Content sounds (chop, work, impact, crit, bounty, levelUp, error, cast) are your game's to give.

Stereo or HRTF ​

'stereo' pans a sound left or right of the view. 'hrtf' places it around the head with a PannerNode, so ahead and behind differ on headphones. Loudness is the same in both. Every sound takes the mode, including a cinematic's sound on a unit. HRTF costs a little CPU: about 1% of a core with 24 sounds at once (the default limits.voices), against 0.3% in stereo. In code: new SoundPlayer(listener, { mode: 'hrtf' }).

Limits ​

GameView.world.limits.voices (24) is how many sounds play at once; a new one past it is dropped. Raise it for big battles. See Graphics quality › Caps.

Music for menus and scenes is handed from scene to scene through the app's mixer: see Menus. Cinematic music and sound: see Music and sound in cinematics.