O'Reilly logo

HTML5 Web Application Development By Example Beginner's guide by J.M. Gustafson

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required