Game Development Reference
In-Depth Information
p.reset = function () {
this.shouldDie = false;
}
window.game.Bullet = Bullet;
}(window));
Similarly to the EnemyShip class, the bullet sprite has properties for speed and its next position, plus a Boolean
value to determine its fate in the next render cycle. The sprite consists of two frames, so it is initially paused on frame
one, which is the red bullet for the hero. This will be advanced to frame 2 for enemies from within the game code.
An object pool will also be created for the bullets, so a reset function is needed to reset the object for later use. The
Explosion class will be recycled in a similar way, as shown in Listing 11-7.
Listing 11-7. The Explosion Class, Declared in Explosion.js
(function (window) {
window.game = window.game || {}
function Explosion() {
this.initialize();
}
var p = Explosion.prototype = new createjs.Sprite();
p.Sprite_initialize = p.initialize;
p.initialize = function () {
this.Sprite_initialize(spritesheet, 'explosion');
this.paused = true;
}
p.reset = function(){
this.gotoAndStop('explosion');
}
window.game.Explosion = Explosion;
}(window));
Creating the HUD
The acronym HUD stands for heads-up display . These are typically the messaging elements that are persistent during
a game level. In Space Hero, three HUD elements are needed. The health meter, score, and life indicators are all
sprites that make up the HUD in the game.
Reviewing the HUD Sprite Frames
There are a few animations and static frames that make up the graphics for the HUD game elements. The frames used
for these HUD sprites are shown in Figure 11-6 .
 
Search WWH ::




Custom Search