Skip to main content

Documentation Index

Fetch the complete documentation index at: https://v5.rpgjs.dev/llms.txt

Use this file to discover all available pages before exploring further.

Create sounds

Sounds are declared on the client, then triggered from the client or the server.

Register sounds on the client

import { provideClientModules } from "@rpgjs/client";

provideClientModules([
  {
    sounds: [
      {
        id: "item-pickup",
        src: "sounds/item-pickup.mp3"
      },
      {
        id: "battle-theme",
        src: "sounds/battle-theme.mp3"
      }
    ]
  }
]);

Play a sound for one player

player.playSound("item-pickup");

Play a sound for the whole map

map.playSound("battle-theme", {
  volume: 0.8,
  loop: true
});

Add map ambience

Maps can automatically play sounds when the player joins:
provideServerModules([
  {
    maps: [
      {
        id: "town",
        sounds: ["town-bgm", "town-ambience"]
      }
    ]
  }
]);

More details

See Sounds Guide for dynamic sound loading, stop strategies, and full audio examples.