This demo demonstrate a utility class to mix two sounds by fading one sound out while fading another sound in.
Its very useful to change music between levels or when entering a boss fight.
Transition Speed:
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 music assets
let music1 = await Shaku.assets.loadSound('assets/music1.ogg');
let music2 = await Shaku.assets.loadSound('assets/music2.ogg');
// create a mixer between the music, allowing them to overlap in the process
let overlapping = true;
let mixer = new Shaku.sfx.SoundMixer(Shaku.sfx.createSound(music1), Shaku.sfx.createSound(music2), overlapping);
// or, create a fade-in for music2 (if first music is null, its a fade in. if second music is null, its a fade out.)
let fadeIn = new Shaku.sfx.SoundMixer(null, Shaku.sfx.createSound(music2), true);
// part below goes between startFrame() and endFrame()
// -------------------------------------------------------
// update mixer with delta time (will take ~1 second to finish):
mixer.updateDelta(Shaku.gameTime.delta);
// or, update fade in mixer to a specific value (50% faded in):
fadeIn.update(0.5);