Appearance
RpgSound
- You have to create a sound with the
Sound
decorator - You can then use the sound when starting a amp, an animation or any action
Sound Decorator
Example:
ts
import { Sound } from '@rpgjs/client'
@Sound({
id: 'town-music',
sound: require('./sound/town.ogg')
})
export class TownMusic {}
Put the created class in the RpgClient decorator
Properties
sound
- Property:
sound
- Type:
string
- Optional:
true
- Usage:
The link to the sound
Do not use the
images
property Remember to wrap the link to the image with therequire
function.
ts
sound: require('./assets/sound.ogg')
loop
- Property:
loop
- Type:
boolean
- Optional:
true
- Usage:
The sound will restart at the beginning when it is finished.
volume
- Property:
volume
- Type:
number
- Optional:
true
- Usage:
Volume
id
- Property:
id
- Type:
string
- Optional:
true
- Usage:
Sound identifier.
Do not use the
sounds
property
sound
- Property:
sound
- Type:
string
- Optional:
true
- Usage:
The link to the sound
Do not use the
images
property Remember to wrap the link to the image with therequire
function.
ts
sound: require('./assets/sound.ogg')
sounds
- Property:
sounds
- Type:
{ [id: string]: string }
- Optional:
true
- Usage:
Put the different sounds that are concerned by the properties below. The key of the object is the identifier of the sound and the value and the link to the sound.
Remember to wrap the link to the sound with the
require
function.
ts
sounds: {
hero: require('./assets/sound.ogg')
}
Use RpgSound
Use the RpgSound class to edit the sound:
ts
import { RpgSound } from '@rpgjs/client'
RpgSound.get('town-music').play()
All sound methods come from the HowlerJS library:
https://github.com/goldfire/howler.js#methods
Global Sound
You can globally manage all the sounds. For example, decrease the volume globally
ts
import { RpgSound } from '@rpgjs/client'
RpgSound.global.volume(0.2)
All sound methods come from the HowlerJS library: