System·phaserthree·v1.0.0·MIT
Audio Manager
Web Audio-based SFX and music manager with named buses, volume control, and pluggable buffer loading. Engine-agnostic.
#audio#sound#music#web-audio
Install
npx gamecn add audio-managerSource preview
Compatibility
| Engines | phaser >=3.80.0 <4.0.0three >=0.160.0 |
| Frameworks | vanilla, react |
| Languages | typescript |
| Bundlers | vite |
Files installed
- {systems}/AudioManager.ts
- docs/gamecn/audio-manager.md(docs)
Notes
Usage
import { AudioManager } from "@/systems/AudioManager";
const audio = new AudioManager();
// Resume context on first user gesture
window.addEventListener("pointerdown", () => audio.unlock(), { once: true });
// Load + play
await audio.loadFromUrl("jump", "/assets/sfx/jump.wav");
audio.play("jump", { bus: "sfx", pitchVariance: 50 });
// Music with loop
await audio.loadFromUrl("theme", "/assets/music/theme.mp3");
const music = audio.play("theme", { bus: "music", loop: true });
// Adjust volume from settings UI
audio.setBusVolume("master", 0.8);
audio.setBusVolume("music", 0.4);
// Stop everything
audio.stopAll();Buses
Default buses: master, sfx, music. All non-master buses route through
master, so setBusVolume("master", v) affects everything.
Custom buses:
const audio = new AudioManager({
buses: { master: 1, sfx: 1, music: 0.7, ui: 0.5, voice: 1 },
});Notes
- Browsers gate
AudioContextuntil the first user gesture. Callunlock()in a click/touch handler. pitchVariance(cents) is great for SFX variety — same shot, slightly different pitch each time.loadFromBuffer(key, ArrayBuffer)if you already have raw bytes (Phaser's loader, custom fetch, etc).
Related
- Dialogue SystemSystem
Branching JSON-driven dialogue runner with choices and variables. Engine-agnostic — bring your own UI renderer.
- Input ManagerUtility
Engine-agnostic input action mapper. Map logical actions ('jump', 'left') to keyboard bindings and query state without coupling gameplay code to the DOM keyboard API.
- Mobile JoystickComponent
On-screen virtual joystick for touch input. Renders to a DOM element; exposes a 2D vector for gameplay. Engine-agnostic.
- Save LoadUtility
Type-safe localStorage-backed save system with versioning and migrations. Engine-agnostic.