HTML and CSS Reference
In-Depth Information
this.addChild(text);
}
NumberBox.prototype = Object.create(game.Box.prototype);
return NumberBox;
})();
}).call(this);
5. Then, we want to place the numbered box on the stage. We need an array to keep
track of all the generated boxes:
game.gameView = {
numberBoxes: [],
// existing gameView code here
}
6. Generaing a box means simply creaing a box instance and puing it on the stage.
However, we make it more fun by adding a random x posiion:
game.gameView = {
generateNumberBox: function(){
// helper function that returns a random integer value between
min and max, both included.
function randomInt(min, max) {
return Math.floor(Math.random() * (max-min+1) + min);
}
var value = randomInt(1, 12) * randomInt(1, 12);
var box = new game.NumberBox(value);
box.x = Math.random() * (game.setting.gameWidth - game.
setting.boxWidth);
box.y = 0;
game.stage.addChild(box);
this.numberBoxes.push(box);
},
// existing gameView code here
}
7. Now, we can start generaing the box by calling the generateNumberBox()
funcion. During the game view iniializaion, we generate the box:
game.gameView = {
init: function() {
this.generateNumberBox();
},
// existing gameView code here
}
 
Search WWH ::




Custom Search