为什么果实不能循环啊?
求大神帮忙看一下,sendFruit()中的i总是为0,这是为什么呀?
var fruitObj = function(){
this.alive = []; //bool
this.x=[]; //图片的x坐标
this.y=[]; //图片的y坐标
this.l=[]; //图片的长度
this.spd=[];
this.orange = new Image(); //创建一个image对象,给浏览器缓存一张图片
this.blue = new Image();
}
fruitObj.prototype.num=30;
fruitObj.prototype.init=function(){
for(var i =0;i<this.num;i++){
this.alive[i]=false;
this.x[i]=0;
this.y[i]=0;
this.l[i]=0;
this.spd[i]=Math.random()*0.017+0.003; //[0.003-0.02)
}
this.orange.src="./src/fruit.png";
this.blue.src="./src/blue.png";
}
fruitObj.prototype.draw = function(){
for(var i =0;i<this.num;i++){
if(this.alive=true){
if(this.l[i]<14){
this.l[i] +=this.spd[i]*deltaTime;//随着时间变大
}else{
this.y[i] -=7*deltaTime*this.spd[i];//y坐标随着时间减小
}
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]);
}
//draw
//find an ane,grow,fly up
if (this.y[i]<-10000) {
this.alive[i] = false;
}
}
}
fruitObj.prototype.update=function(){
var num = 0;
for(var i=0;this.num;i++){
if(this.alive[i])
num++;
}
}
// 水果找到一个海葵出生
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.alive[i]=true;
// console.log(fruit.alive[i]);
}
function fruitMonitor(){
var num = 0;
console.log(fruit.alive[i]);
for(var i = 0; i< fruit.num;i++){
if(fruit.alive[i])
num++;
}
if(num<15){
sendFruit();
return;
}
}
function sendFruit(){
for(var i = 0; i<fruit.num;i++){
if(!fruit.alive[i])
{
fruit.born(i);
// console.log(i);
return;
}
}
}