Game Development Reference
In-Depth Information
Preparing the Asset Manager
The AssetManager class is nearly identical to the one built in Chapter 9. The functionality is the same, but the actual
assets will be different. Similar to application class, the AssetManager.js file can be reused, only this time, the code
that lists and loads the assets should be changed to fit the application. Listing 11-3 shows the list of assets being
declared and loaded in the initialize function.
Listing 11-3. The Assets Added and Loaded in the AssetManager Class
//sounds
p.EXPLOSION = 'explosion';
p.SOUNDTRACK = 'soundtrack';
//graphics
p.GAME_SPRITES = 'game sprites';
//data
p.GAME_SPRITES_DATA = 'game sprites data'
//events
p.ASSETS_PROGRESS = 'assets progress';
p.ASSETS_COMPLETE = 'assets complete';
p.assetsPath = 'assets/';
p.loadManifest = null;
p.queue = null;
p.loadProgress = 0;
p.initialize = function () {
this.EventDispatcher_initialize();
this.loadManifest = [
{id:this.EXPLOSION, src:this.assetsPath + 'explosion.mp3|' +
this.assetsPath + 'explosion.ogg'},
{id:this.SOUNDTRACK, src:this.assetsPath + 'dreamRaid1.mp3|' +
this.assetsPath + 'dreamRaid1.ogg'},
{id:this.GAME_SPRITES_DATA, src:this.assetsPath + 'sprites.json'},
{id:this.GAME_SPRITES, src:this.assetsPath + 'sprites.png'}
];
}
Creating the Application Class
The ExplodingAsteroids.js class was the main application script used in the Exploding Asteroids exercise built in
Chapter 10. The state machine that will run the game in this chapter uses the same scene names, and the state events
used will be identical. This class can be used to fit the needs for Space Hero. Create a copy and change the name of the
file to SpaceHero.js .
 
Search WWH ::




Custom Search