Sfx manager. Used to play sound effects and music.
To access the Sfx manager use Shaku.sfx
.
Kind: global class
Number
Number
Promise
SoundInstance
Create the manager.
Get the SoundMixer class.
Kind: instance property of Sfx
See: SoundMixer
Number
Get currently playing sounds count.
Kind: instance property of Sfx
Returns: Number
- Number of sounds currently playing.
Number
Get 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. |
Promise
Play 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();
SoundInstance
Create 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();