HTML and CSS Reference
In-Depth Information
2. The energy enity is ready. We use it in the satellite.js file. We add the
following frequent controls and a tick interval to the Satellite constructor:
function Satellite(){
...
// existing code
this.energyFrequency = 500;
this.ticks = 0;
this.on('tick', this.tick);
}
3. On each tick of Satellite , we check whether it is a good ime to generate new
energy based on the frequency:
Satellite.prototype.tick = function() {
if (cjs.Ticker.getPaused()) { return; }
this.ticks += 1;
// summon energy
if (this.ticks % this.energyFrequency === 0) {
this.summonEnergy();
}
};
4. Then, we create the summonEnergy method to actually visualize the energy bubble
into the stage:
Satellite.prototype.summonEnergy = function() {
var pos = this.localToLocal(0, 0, game.effectLayer);
var energy = new game.Energy(pos.x, pos.y);
game.effectLayer.addChild(energy);
};
5. To illustrate how we can create more levels of the same type of building, we create
a second level of satellite based on the first level. It generates energy at a higher
frequency. Also, make sure we charge more energy for premium buildings:
this.energyFrequency = 100;
 
Search WWH ::




Custom Search