Chapter 6. Adding Sound Effects to Your Games
In the earlier chapters, we discussed several techniques to draw game objects visually. In this chapter, we will focus on using the audio
tag that is introduced in the HTML5 specification. We can add sound effects, background music, and control the audio through the JavaScript API. In addition, we will build a music game in this chapter. It is a game that requires players to hit the correct string at the right time to produce the music.
In this chapter, you will learn the following topics:
- Adding a sound effect to the Play button
- Building a mini piano musical game
- Linking the music game and the Play button
- Adding keyboard and touch inputs to the game
- Creating a keyboard-driven music game
- Completing the musical game with a level data recording and the game over event
You can play the game example at: http://makzan.net/html5-games/audiogame/.
The following screenshot shows the final result we will create through this chapter:
So, let's...