Sound
⚠️
This page is under construction.
⚠️
Beta feature, subject to change.
Sound controls the sound of the game
Public Method
constructor
Overload 1 of 2
config?: Partial<ISoundUserConfig>
- See ISoundUserConfig
Overload 2 of 2
src?: string
- The source of the sound
Chainable Method
play
Play the sound
const sound = new Sound({
src: 'sound.mp3',
});
scene.action([
sound.play(1000), // play and fade in 1 second
]);
duration?: number
- Fade duration in milliseconds
stop
Stop the sound. After stopping, the sound will go back to the beginning
duration?: number
- Fade duration in milliseconds
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 1duration?: number
- Fade duration in milliseconds
setRate
Set the rate of the sound
rate: number
- Rate, base is 1
pause
duration?: number
- Fade duration in milliseconds
resume
fade?: number
- Fade duration in milliseconds