我不能让我的VAR计数跟踪计数的if语句谁能帮助我我不能让我的变种数右
Laser.prototype.update = function() {
//.3
this.rot += .3
this.pos.add(this.dir.clone().mult(5));
this.alive = !(this.pos.x > cw || this.pos.x < 0 || this.pos.y > ch || this.pos.y < 0);
var counts = 0;
for (var i = 0; i < asteroids.length; i++) {
var astPos = asteroids[i].pos.clone();
astPos.sub(this.pos); //3 impact area
if (asteroids[i].onscreen && astPos.len() < asteroids[i].sizes[asteroids[i].level] + 10) {
asteroids[i].hit(this.dir);
if (counts < 5) {
this.alive = false;
counts++;
//alert("the count is" + counts);
}
if (counts > 5) {
this.alive = true;
counts++;
alert("the count is" + counts);
}
return counts;
}
}
}
究竟是什么问题?它根本不算数吗?它在某些情况下不计算在内吗?它跳过数字吗?有错误吗?你有什么想法“它应该如何计数”? – newfurniturey 2013-03-08 04:08:15
让我猜:' .update()'总是返回'1'? –
Passerby
2013-03-08 04:09:01
提示:使用'console.log'而不是'alert'。你已经提供了代码 - 这很好 - 但你忘了在你的问题中实际提出一个问题。 – Phrogz 2013-03-08 04:09:56