HTML and CSS Reference
In-Depth Information
2. Then, we draw the boundary line when gameView iniializes:
game.gameView = {
init: function() {
// boundary line
var line = new game.RectShape(game.setting.gameWidth, 3,
{fillColor:'#600'});
line.y = game.setting.lineY;
game.stage.addChild(line);
// existing init code goes here.
},
}
3. Once a box falls below the boundary, we will remove it. Add the following funcion
to the game view so that we can remove a specific box:
game.gameView = {
removeNumberBox: function(target) {
for (var i=0, len=this.numberBoxes.length; i<len; i++) {
var box = this.numberBoxes[i];
if (box === target) {
this.numberBoxes.splice(i, 1);
game.stage.removeChild(box);
return;
}
}
},
// existing gameView code goes here
};
4. Now, after the game loop makes the boxes fall, we loop through each object and
remove any boxes that are below the boundary line:
game.gameView = {
moveObjects: function() {
// existing move objects code goes here.
for (var i=0, len=this.numberBoxes.length; i<len; i++) {
var box = this.numberBoxes[i];
// remove the box when it is below deadline
if (box.y>game.setting.boundaryY) {
this.removeNumberBox(box);
}
}
},
// existing gameView code goes here
};
 
Search WWH ::




Custom Search