mercredi 28 janvier 2015

Prototype applied for only one object

I just got a little problem in my code.


I've 3 objects defined by a 'class' and when I call this method, it's only executing for the first object.



Box.prototype.hit = function() {

if (controller.space) {
// Si player détectée en diagonal
if (this.id - 12 === player.id) {
console.log(this);
// Décalage en diagonale de la position de la box
this.x += this.boxWidth;
this.y += this.boxHeight;
currentLevel[this.id] = 0;
this.id += 12;
currentLevel[this.id] = 2;
}
controller.space = false;
}
}


In this code, the second if is testing the id of the first object defined and the others are not spotted. However I have prototypes like this which are working.


Thanks for help.


Aucun commentaire:

Enregistrer un commentaire