HTML and CSS Reference
In-Depth Information
Engage thrusters
Let's work on energy generaion:
1. The graphics are defined in the assets.js file, but we will add more logic to the
sprite with the energy.js file:
;(function(game, cjs, lib){
function Energy(x, y) {
cjs.Container.call(this); //super
this.addChild(new lib.Energy());
this.cache(-25, -25, 50, 50); // cache the bitmap to improve
performance.
this.x = x || 0;
this.y = y || 0;
this.baseX = this.x; // store the original X
// Tween animation
cjs.Tween.get(this, {loop: true}).to({scaleX:1.2, scaleY:1.2},
600).to({scaleX:1.0, scaleY:1.0}, 600);
// tick the movement
this.on('tick', this.tick);
this.on('mousedown', this.onclick);
}
Energy.prototype = Object.create(cjs.Container.prototype);
Energy.prototype.tick = function(){
if (cjs.Ticker.getPaused()) { return; }
var offsetX = Math.sin(cjs.Ticker.getTicks()/10) * 20;
this.x = this.baseX + offsetX;
this.y -= .5;
};
Energy.prototype.onclick = function(e){
game.energies += 100;
this.parent.removeChild(this);
};
game.Energy = Energy;
}).call(this, game, createjs, lib);
 
Search WWH ::




Custom Search