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 aLoadedAudio object from stateApp.loadedAssets (populated by pixi-svelte).
Howl instance and three Player instances:
Player methods
Each player insound.players exposes:
Playback examples
Type reference
Volume system
Volume is controlled globally viastateSound from state-shared. All three players observe this state via Svelte $effect.
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:
components-ui-pixi expose a ButtonSoundSwitch component that lets the player toggle sound on/off by writing to stateSound.volumeValueMaster.
