Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.

  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

6. Working With Sound > Adding Sounds

Adding Sounds

In order to add sound to our game, we are going to have to use the ig.Sound class. Impact supports two file formats: Ogg Vorbis and MP3. The ig.SoundManager class can automatically detect which file to load based on the browser. Here are some examples of how to set up an ig.Sound instance:

var sound = new ig.Sound( 'media/sounds/jump.ogg' );
var sound = new ig.Sound( 'media/sounds/jump.mp3' );
var sound = new ig.Sound( 'media/sounds/jump.*' );

The last example is a wild card that lets the ig.SoundManager automatically load the correct file for us. Our sound files, just like images, should live inside the media directory. I also keep them in a subdirectory called sounds, so they stay organized. Let’s add some sound effects to our player. Open the player.js class and set up the following properties at the top of our player class:


  

You are currently reading a PREVIEW of this book.

                                                                                                                    

Get instant access to over $1 million worth of books and videos.

  

Start a Free 10-Day Trial


  
  • Safari Books Online
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint