# Put sounds and music

# Prerequisites

  1. You must have an sound

# Structure

Here is the structure:

  • src
    • client
      • sounds
        • assets
          • my-music.ogg
        • index.ts

# Create music

import { Sound } from '@rpgjs/client'

    sounds: {
        town: require('./my-music/music.ogg'),
    loop: true
export class Musics {}
  • town is the identifier of the resource. We indicate that the sound will be played in a loop because it is a music for a map

Then add the sound in a module. For your main game, add it to the src/modules/main/client/index.ts file

import { RpgModule, RpgClient } from '@rpgjs/client'
import { Sounds } from './sounds'

    sounds: [
export default class RpgClientEngine {}

# Use sound in the game

As soon as a map is opened:

import { RpgMap, MapData } from '@rpgjs/server'

    id: 'medieval',
    file: require('./tmx/medieval.tmx'),
    name: 'Town',
    sounds: ['town'] // You can add several musics
export class MedievalMap extends RpgMap { }