This demo demonstrate how to play basic sounds with Shaku.
Press 1-9 to play drum sound with different pitch.
Press b to toggle birds ambience sound.
Due to browsers security features, you can't play any sounds via code before the user interacts with the page.
Drums Playing:
The following is a minimal code example on how to use the SFX manager. These are just the basics, for the full API please see the docs.
Keep in mind you also need to call Shaku.init(), Shaku.startFrame() and Shaku.endFrame(), which are mandatory for all examples and omitted for simplicity.
// load sound asset
let soundAsset = await Shaku.assets.loadSound('assets/drum.ogg');
// play sound once
Shaku.sfx.play(soundAsset, volume, pitch);
// create sound instance and play it in a loop
// sound instances are also more efficient than sfx.play() if you need to repeat the same sound lots of times (for example steps sound or gun blasts).
let soundInstance = Shaku.sfx.createSound(soundAsset);
soundInstance.loop = true;
soundInstance.play();
// stop looping sound
soundInstance.stop();