@nanoforge-dev/sound
v3.0.0
Published
NanoForge Engine - Sound
Readme
About
@nanoforge-dev/sound is NanoForge's built-in sound-effect library. It manages a collection of named HTMLAudioElement instances exposed on Context.sound. Unlike @nanoforge-dev/music, multiple sounds may overlap — there's no single-track exclusivity.
Installation
Node.js 26 or newer is required.
npm install @nanoforge-dev/sound
yarn add @nanoforge-dev/sound
pnpm add @nanoforge-dev/sound
bun add @nanoforge-dev/soundExample usage
Register SoundLibrary on your client app:
import { SoundLibrary } from "@nanoforge-dev/sound";
app.use(new SoundLibrary());Load and play sound effects through Context.sound:
public override async __init(): Promise<void> {
ctx.sound.load("jump", "/assets/jump.wav");
ctx.sound.load("hit", "/assets/hit.wav");
}
public override async __run(ctx: Context): Promise<void> {
if (playerJumped) ctx.sound.play("jump");
}Call ctx.sound.mute() to toggle the muted state of every loaded sound effect. play throws NfNotFound when the given key was never loaded.
Links
Contributing
Before creating an issue, please ensure that it hasn't already been reported/suggested, and double-check the
documentation.
See the contribution guide if you'd like to submit a PR.
Help
If you don't understand something in the documentation, you are experiencing problems, or you just need a gentle nudge in the right direction, please don't hesitate to ask questions in discussions.
