园子
2016-03-28 21:14
绘制静态果实的时候可以显示,但是添加上this.l[] 之后 在draw中打印this.l[i]时显示NaN
var fruitObj = function(){
this.alive = [];
this.x = [];
this.y = [];
this.l = [];
this.orange = new Image();
this.blue = new Image();
}
fruitObj.prototype.num = 30 ;
fruitObj.prototype.init =function(){
for (var i = 0; i < this.num; i++) {
this.alive[i] = true;
this.x[i] = 0 ;
this.y[i] = 0;
this.born(i);
}
this.orange.src="./src/fruit.png";
this.blue.src = "./src/blue.png";
}
fruitObj.prototype.draw = function(){
for (var i = 0; i < this.num; i++) {
//draw find an ane ,grow,fly up
console.log(this.l[i]);
this.l[i] += 0.01 * deltaTime;
ctx2.drawImage(this.orange,this.x[i] - this.l[i]*0.5 ,this.y[i]- this.l[i]*0.5,this.l[i],this.l[i] );
}
}
//随机找一个海葵,果实长在海葵上
fruitObj.prototype.born = function(i){
var aneID = Math.floor(Math.random()*ane.num);
this.x[i] = ane.x[aneID]
this.y[i] = canheight - ane.len[aneID];
this.l[i] = 0;
}
确实this.l[i]返回值为NaN,不是一个数字,到现在也没有找到问题出在哪儿
HTML5小游戏---爱心鱼(上)
92344 学习 · 579 问题
相似问题