Game Development Reference
In-Depth Information
this.x += this.speed;
if(this.x > stage.canvas.width){
this.x = -this.getBounds().width;
}
})
}
p.run = function () {
if (this.currentAnimation === 'idle') {
this.gotoAndPlay('run');
this.speed = 10;
}
}
p.jump = function () {
if (this.currentAnimation != 'jump') {
this.gotoAndPlay('jump');
this.on('animationend',function(e){
if(this.speed > 0){
this.gotoAndPlay('run');
}
})
}
}
p.stand = function () {
if (this.currentAnimation === 'run') {
this.gotoAndStop('idle');
this.speed = 0;
}
}
window.sprites. Runner = Runner;
}());
Preloading and Initializing the Application
With The Runner class now complete, jump into the runningMan . js file (see Listing 8-20). The application code will
begin with some declared variables and the preload function, which is called when the body is loaded.
Listing 8-20. runningMan.js, Variables and preload Function
var stage, queue, preloader, spritesheet, runner;
function preload() {
queue = new createjs.LoadQueue();
queue.loadManifest([
{id:"runner", src:"img/runningMan.png"}
],false);
init();
}
 
Search WWH ::




Custom Search