HTML and CSS Reference
In-Depth Information
var userDataB = contact.GetFixtureB().GetBody().GetUserData();
if (userDataA !== null && userDataA.isBoundary ||
userDataB !== null && userDataB.isBoundary) {
// which one is boundary?
var boundary = contact.GetFixtureA().GetBody();
var body = contact.GetFixtureB().GetBody();
if (userDataB !== null && userDataB.isBoundary) {
boundary = contact.GetFixtureB().GetBody();
body = contact.GetFixtureA().GetBody();
}
physics.bodiesToRemove.push(body);
}
};
this.world.SetContactListener(contactListener);
};
7. Remember the array for body removal? We now use it in the update funcion.
We iterate the list and destroy each body in that array:
physics.update = function() {
// existing code goes here.
// remove bodies
for (var i=0, len=this.bodiesToRemove.length; i<len; i++) {
var body = this.bodiesToRemove[i];
var sprite = body.GetUserData();
if (sprite) {
sprite.parent.removeChild(sprite);
}
this.world.DestroyBody(body);
}
this.bodiesToRemove.length = 0;
};
8. We can now move to the game.js file where we init the game score:
game.score = 0;
9. We define the following method to increase the game score:
game.increaseScore = function() {
game.score += 1;
console.log(game.score); // out to console until we display it
in interface.
};
 
Search WWH ::




Custom Search