Game Development Reference
In-Depth Information
msgContainer.addChild(txt);
//add and position container
this.addChild(msgContainer);
msgContainer.x = msgPos.x;
msgContainer.y = msgPos.y;
msgContainer.cache(0, 0, msgWidth, msgHeight);
}
p.getBitmapTxt = function (txt, x, y) {
var txt = new createjs.BitmapText(txt, fontsheet);
txt.letterSpacing = 6;
txt.x = x;
txt.y = y;
return txt;
}
p.addShop = function () {
var shop = new game.MagicShop();
shop.x = 20;
shop.y = 550;
this.addChild(shop);
}
p.drawContinueButton = function () {
var btn = new createjs.Sprite(spritesheet, 'continueBtn');
btn.x = (screen_width / 2) - (btn.getBounds().width / 2);
btn.y = 1020;
btn.on('click', this.onButtonClick, this);
this.addChild(btn);
}
p.onButtonClick = function (e) {
this.dispatchEvent(game.GameStateEvents.LEVEL_SELECT);
}
window.game.LevelComplete = LevelComplete;
}());
The very first thing the class does is update the level and stats of the player. The methods updateLevel and
updateStats handle this by accessing and manipulating the PlayerData object, which will write to local storage.
The current stats values are all referenced and saved to class properties. This is so they can be easily accessed when
drawing the messages. The values are then added and saved by being assigned to the player object in PlayerData .
Next, a background sprite is added, followed by the messaging in the addLevelMessaging method. This function
creates a series of bitmap text objects to display the proper messages pertaining to what was gained and what the
player now has. This includes power, defense, max hit point count, and coins. A little utility function, getBitmapTxt ,
is used to create and return the bitmap text objects as the messages are built. The complete messaging section of the
level complete screen is shown in Figure 14-17 .
Search WWH ::




Custom Search