Game Development Reference
In-Depth Information
Creating the Battle Action Buttons
The BattleButton class draws the action button, which properly displays the quantity of the items it represents and
enables itself accordingly. At this point in the topic, you should be able to understand what is going in the class' code,
but I will highlight some of the important areas after you review the entire class (see Listing 14-31).
Listing 14-31. BattleButton.js - The BattleButton Class for Player Actions
(function () {
window.game = window.game || {}
function BattleButton(frame, quantity) {
this.initialize(frame, quantity);
}
var p = BattleButton.prototype = new createjs.Container();
p.Container_initialize = p.initialize;
p.quantityTxt = null;
p.frame = null;
p.type = null;
p.quantity = null;
p.isDown = null;
p.initialize = function (frame, quantity) {
this.Container_initialize();
this.isDown = false;
this.frame = this.type = frame;
this.quantity = (quantity * 1);
this.addSprite();
this.setQuantity();
this.cacheButton();
this.enableButton();
}
p.addSprite = function () {
var sprite = new createjs.Sprite(spritesheet, this.frame);
var bounds = sprite.getBounds();
this.setBounds(0, 0, bounds.width, bounds.height);
this.regX = bounds.width / 2;
this.regY = bounds.height;
this.addChild(sprite);
}
p.setQuantity = function () {
if (this.quantity >= 0) {
var xPos = 25;
var yOffset = 28;
var yPos = this.getBounds().height - yOffset;
 
Search WWH ::




Custom Search