Binding the external JavaScript library
In our Pacman game, we need to preload game resources such as images and sounds. We need to play sounds and music as well. Of course, we could write our own code to accomplish these tasks. However, why reinvent the wheel? There are numerous JavaScript libraries that make our job easier. The following section shows how to bind an existing JavaScript library into our game.
Preloading the resources
When a program requires multiple images and sounds, as is the case with our Pacman game, it's usually a good idea to load all of the resources before displaying or playing them. There are many excellent JavaScript libraries available. For our purposes, the Preload JS 0.3.0 (for resource) and SoundJS 0.4.0 (for sounds) libraries are a good fit. You can download Preload JS 0.3.0 from https://github.com/CreateJS/PreloadJS and the SoundJS 0.4.0 library is available at https://github.com/CreateJS/SoundJS.
To bind the JavaScript library, we must register those functions...