Sound
⚠️
This page is under construction.
⚠️
Beta feature, subject to change.
Sound controls the sound of the game
Static Method
voice
Create a voice sound
const voice = Sound.voice({
src: 'voice.mp3',
});
// is equivalent to
const voice = new Sound({
src: 'voice.mp3',
type: SoundType.Voice,
});
arg0: Partial<ISoundUserConfig> | string
- The config of the sound or the source of the sound, see ISoundUserConfig- Returns
Sound
bgm
Create a bgm sound
arg0: Partial<ISoundUserConfig> | string
- The config of the sound or the source of the sound, see ISoundUserConfig- Returns
Sound
sound
Create a sound
arg0: Partial<ISoundUserConfig> | string
- The config of the sound or the source of the sound, see ISoundUserConfig- Returns
Sound
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 and wait for it to finish
Note: Sounds marked as
Bgm
cannot be played directly.
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