Time for action – adding the audio sequencer
Let's add the audio sequencer to the game panel. We will go into the GamePanel
object and add an instance of AudioSequencer
to it:
function GamePanel(audioManager) { var sequencer = new AudioSequencer();
Next let's write the public setOptions()
method, which is called from the startGame()
method of PianoHeroApp
. It takes three parameters; the song name, playback rate, and whether to play the game or the song in practice mode:
this.setOptions = function(songName, rate, playGame) { sequencer.events(musicData[songName]) .playbackRate(rate); practiceMode = !playGame; return this; };
The first thing we do is set the events()
property of the audio sequencer to the data for the song to play. We get the song data from the musicData
object, which is defined in musicData.js
. Then, we set the audio sequencer's playbackRate()
property. Lastly we set the practiceMode
variable.
The musicData...