Book Image

HTML5 Game Development by Example: Beginner's Guide

By : Seng Hin Mak
Book Image

HTML5 Game Development by Example: Beginner's Guide

By: Seng Hin Mak

Overview of this book

Table of Contents (18 chapters)
HTML5 Game Development by Example Beginner's Guide Second Edition
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
9
Building a Physics Car Game with Box2D and Canvas
Index

Time for action – creating the playback visualization in the music game


In order to create the playback visualization in the music game, you'll need to carry out the following steps:

  1. We need a song with both a melody part and a base part. Copy the minuet_in_g.ogg, minuet_in_g.aac, minuet_in_g_melody.ogg, and minuet_in_g_melody.aac files from the downloaded files or from the code bundle in the media folder.

  2. Then, add the audio tag with the song as a source file. Open the index.html file and add the following code:

    <audio id="melody">
      <source src="media/minuet_in_g_melody.aac" />
      <source src="media/minuet_in_g_melody.ogg" />
    </audio>
    
    <audio id="base">
      <source src="media/minuet_in_g.aac" />
      <source src="media/minuet_in_g.ogg" />
    </audio>
  3. The music visualization is mainly done in JavaScript. Open the audiogame.js JavaScript file in a text editor.

  4. Add a MusicNote object type to represent the music data and a Dot object type to represent the...