Game Development Reference
In-Depth Information
These values will be used when building the manifest for the load queue. You'll also need to declare a property
for this queue, along with a few others, shown in Listing 9-6.
Listing 9-6. Properties for the AssetManager Class
p.queue = null;
p.assetsPath = 'assets/';
p.loadManifest = null;
p.loadProgress = 0;
Along with the queue, the assets path is created for use when building the manifest, which will also be stored as a
property named loadManifest . Lastly, a loadProgress property is made so the progress can be easily accessed from
outside the class. Next, a few event strings are declared in Listing 9-7.
Listing 9-7. Events Used in AssetManager
//events
p.ASSETS_PROGRESS = 'assets progress';
p.ASSETS_COMPLETE = 'assets complete';
These strings will be the names of the events that are dispatched from the class. As with manifest ids , events are
created using simple strings, so setting them to the value of a property makes it much easier to access in the future.
Now that the properties are set, the manifest needs to be built so it can be loaded into PreloadJS.
Preloading in the AssetManager Class
The manifest will be built directly in the initialize method, which assures you that all property values have been set
and ready to use. Listing 9-8 extends on to the initialize method.
Listing 9-8. Creating a Load Manifest
p.initialize = function () {
this.EventDispatcher_initialize();
this.loadManifest = [
{id:this.EXPLOSION, src:this.assetsPath + 'explosion.mp3'},
{id:this.SHIP_FIRE, src:this.assetsPath + 'fire.mp3'},
{id:this.POWER_UP, src:this.assetsPath + 'powerup.mp3'},
{id:this.SOUNDTRACK, src:this.assetsPath + 'dreamRaid1.mp3'},
{id:this.GAME_SPRITES_DATA, src:this.assetsPath +
'gameSpritesData.json'},
{id:this.UI_SPRITES_DATA, src:this.assetsPath +
'uiSpritesData.json'},
{id:this.GAME_SPRITES, src:this.assetsPath + 'gameSprites.png'},
{id:this.UI_SPRITES, src:this.assetsPath + 'uiSprites.png'}
];
}
 
Search WWH ::




Custom Search