Shaku

Shaku JS

Back To Table of Content

Sfx

Sfx

Sfx manager. Used to play sound effects and music.

To access the Sfx manager use Shaku.sfx.

Kind: global class

new Sfx()

Create the manager.

sfx.SoundMixer

Get the SoundMixer class.

Kind: instance property of Sfx
See: SoundMixer

sfx.playingSoundsCount ⇒ Number

Get currently playing sounds count.

Kind: instance property of Sfx
Returns: Number - Number of sounds currently playing.

sfx.masterVolume ⇒ Number

Get master volume. This affect all sound effects volumes.

Kind: instance property of Sfx
Returns: Number - Current master volume value.

sfx.masterVolume

Set master volume. This affect all sound effects volumes.

Kind: instance property of Sfx

Param Type Description
value Number Master volume to set.

sfx.play(soundAsset, volume, playbackRate, preservesPitch) ⇒ 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);

sfx.stopAll()

Stop all playing sounds.

Kind: instance method of Sfx
Example

Shaku.sfx.stopAll();

sfx.createSound(sound) ⇒ 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();