Game Development Reference
In-Depth Information
{id:this.BATTLE_BG, src:this.assetsPath + 'battleBG.png'},
{id:this.MENU_BG, src:this.assetsPath + 'menuBG.png'}
];
}
p.preloadAssets = function () {
createjs.Sound.initializeDefaultPlugins();
this.queue = new createjs.LoadQueue();
this.queue.installPlugin(createjs.Sound);
this.queue.on('progress',this.assetsProgress,this);
this.queue.on('complete',this.assetsLoaded,this);
this.queue.loadManifest(this.loadManifest);
}
p.assetsProgress = function (e) {
this.loadProgress = e.progress;
var event = new createjs.Event(this.ASSETS_PROGRESS);
this.dispatchEvent(event);
}
p.assetsLoaded = function (e) {
var event = new createjs.Event(this.ASSETS_COMPLETE);
this.dispatchEvent(event);
}
p.getAsset = function (asset) {
return this.queue.getResult(asset);
}
window.game.AssetManager = AssetManager;
}());
Creating the Device Class
The scaling and device orientation code that was learned in Chapter 12 will be used to create a reusable object
that can be used for this and future games. The purpose of this code will be to extract the screen detection and
functionality from the main application (see Listing 14-3).
Listing 14-3. Device.js - The Device Class Handles Screen Scaling
(function () {
window.game = window.game || {};
var Device = {}
Device.prepare = function () {
if (typeof window.orientation !== 'undefined') {
window.onorientationchange = this.onOrientationChange;
if (createjs.Touch.isSupported()) {
createjs.Touch.enable(stage);
}
 
Search WWH ::




Custom Search