@nanoforge-dev/music
v1.0.1
Published
NanoForge Engine - Music
Downloads
155
Readme
About
@nanoforge-dev/music is a music player for your game.
Installation
Node.js 24.11.0 or newer is required.
npm install @nanoforge-dev/music
yarn add @nanoforge-dev/music
pnpm add @nanoforge-dev/music
bun add @nanoforge-dev/musicExample usage
Initialize the library in your main file
import { AssetManagerLibrary } from "@nanoforge-dev/asset-manager";
import { type IRunClientOptions } from "@nanoforge-dev/common";
import { NanoforgeFactory } from "@nanoforge-dev/core";
import { MusicLibrary } from "@nanoforge-dev/music";
export const MUSIC_SYM = Symbol("music");
export async function main(options: IRunClientOptions) {
const app = NanoforgeFactory.createClient();
const assetManager = new AssetManagerLibrary();
const music = new MusicLibrary();
app.useAssetManager(assetManager);
app.use(MUSIC_SYM, music);
await app.init(options);
music.load("music", assetManager.getAsset("/path/to/music.mp3").path);
await app.run();
}Use to play music
export function mySystem(registry: Registry, ctx: Context) {
const assetManager = ctx.libs.getAssetManager<AssetManagerLibrary>();
const music = ctx.libs.get<MusicLibrary>(MUSIC_SYM);
music.play("music");
}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.
