Sound
⚠️
This page is under construction.
⚠️
Beta feature, subject to change.
Sound controls the sound of the game
There are 4 types of sound:
- soundEffect
- music
- voice
- backgroundMusic
Public Method
constructor
Overload 1 of 2
config?: DeepPartial<SoundConfig>
- See SoundConfig
Overload 2 of 2
src?: string
- The source of the sound
Chainable Method
play
Play the sound
Note:
backgroundMusic
cannot be played with this method
const sound = new Sound({
src: 'sound.mp3',
});
scene.action([
sound.play(),
]);
stop
Stop the sound. After stopping, the sound will go back to the beginning
Note:
backgroundMusic
cannot be stopped with this method
fade
Fade the sound
start: number | undefined
- Start volume, from 0 to 1, default is current volumeend: number
- End volume, from 0 to 1duration: number
- Duration in milliseconds
const sound = new Sound({
src: 'sound.mp3',
volume: 0,
});
scene.action([
sound
.play()
.fade(0, 1, 1000), // fade in 1 second
]);
setVolume
Set the volume of the sound
volume: number
- Volume, from 0 to 1
setRate
Set the rate of the sound
rate: number
- Rate, base is 1
pause
fade?: number
- Fade duration in milliseconds
resume
fade?: number
- Fade duration in milliseconds