
Sfx manager. Used to play sound effects and music.
To access the Sfx manager use Shaku.sfx.
Kind: global class
NumberNumberPromiseSoundInstanceCreate the manager.
Get the SoundMixer class.
Kind: instance property of Sfx
See: SoundMixer
NumberGet currently playing sounds count.
Kind: instance property of Sfx
Returns: Number - Number of sounds currently playing.
NumberGet master volume. This affect all sound effects volumes.
Kind: instance property of Sfx
Returns: Number - Current master volume value.
Set master volume. This affect all sound effects volumes.
Kind: instance property of Sfx
| Param | Type | Description |
|---|---|---|
| value | Number |
Master volume to set. |
PromisePlay a sound once without any special properties and without returning a sound instance. Its a more convinient method to play sounds, but less efficient than ‘createSound()’ if you want to play multiple times.
Kind: instance method of Sfx
Returns: Promise - Promise to resolve when sound starts playing.
| Param | Type | Description |
|---|---|---|
| soundAsset | SoundAsset |
Sound asset to play. |
| volume | Number |
Volume to play sound (default to max). |
| playbackRate | Number |
Optional playback rate factor. |
| preservesPitch | Boolean |
Optional preserve pitch when changing rate factor. |
Example
let sound = await Shaku.assets.loadSound("assets/my_sound.ogg");
Shaku.sfx.play(sound, 0.75);
Stop all playing sounds.
Kind: instance method of Sfx
Example
Shaku.sfx.stopAll();
SoundInstanceCreate and return a sound instance you can use to play multiple times.
Kind: instance method of Sfx
Returns: SoundInstance - Newly created sound instance.
| Param | Type | Description |
|---|---|---|
| sound | SoundAsset |
Sound asset to play. |
Example
let sound = await Shaku.assets.loadSound("assets/my_sound.ogg");
let soundInstance = Shaku.sfx.createSound(sound);
soundInstance.play();