Game Development Reference
In-Depth Information
this.coinsTxt = this.getBitmapTxt('x' + this.totalCoins, xPos, yPos,
.6);
this.addChild(coin, this.coinsTxt);
}
p.getBitmapTxt = function (txt, x, y, scale) {
var txt = new createjs.BitmapText(txt, fontsheet);
txt.letterSpacing = 6;
txt.x = x;
txt.y = y;
txt.scaleX = txt.scaleY = scale != null ? scale : 1;
return txt;
}
p.addItemButtons = function () {
var i, btn, btnWidth, prevButton, txt, cost, magicType;
var btns = ['potion', 'fire', 'earth', 'lightning' ];
var playerData = data.PlayerData.player;
var xPos = 70;
var yPos = 380;
var btnSpacing = 20;
var len = btns.length;
for (i = 0; i < len; i++) {
magicType = btns[i];
cost = this.magicData[magicType];
btn = new game.BattleButton(magicType, playerData[magicType]);
btn.name = 'btn_' + magicType;
btn.on('click', this.purchaseItem, this, false, {cost:cost});
if (cost > this.totalCoins) {
btn.disableButton();
}
btnWidth = btn.getBounds().width;
if (prevButton != null) {
btn.x = ((prevButton.x + (prevButton.getBounds().width / 2)) +
btnWidth / 2) + btnSpacing;
}
else {
btn.x = xPos;
}
btn.y = yPos;
this.addChild(btn);
prevButton = btn;
}
txt = this.getBitmapTxt('CLICK ITEM TO PURCHASE', 20, 400, .6);
this.addChild(txt);
}
p.purchaseItem = function (e, data) {
var player = window.data.PlayerData.player;
var btn = e.currentTarget;
var item = btn.type;
var cost = data.cost;
btn.updateQuantity(1);
player[item] = btn.quantity;
Search WWH ::




Custom Search