Skip to main content
utils-sound wraps Howler.js to provide a structured audio system with three playback modes: looping music, looping sound effects, and one-shot sound effects. Volume levels are automatically synced to the global stateSound from state-shared.

createSound()

Factory function typed by your game’s sound name union. Create one instance per game.

Return value

load()

Must be called once after assets have loaded. Receives a LoadedAudio object from stateApp.loadedAssets (populated by pixi-svelte).
Internally creates a single Howl instance and three Player instances:

Player methods

Each player in sound.players exposes:

Playback examples

Type reference

Volume system

Volume is controlled globally via stateSound from state-shared. All three players observe this state via Svelte $effect.
Call sound.volumeEffect() inside a Svelte component (e.g. the root Game.svelte) to register the reactive effects that keep player volume in sync:

Enable / disable

enableEffect() registers a $effect that calls Howler.mute(true) whenever the tab is hidden or the AudioContext is not running (e.g. the browser blocked autoplay), and Howler.mute(false) when both conditions clear:
The UI components in components-ui-pixi expose a ButtonSoundSwitch component that lets the player toggle sound on/off by writing to stateSound.volumeValueMaster.

Full setup example