我的果實(shí)也沒出來
var fruitObj = function(){
this.alive = [];
this.x=[];
this.y=[];
this.huang = new Image();
this.lan = 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.huang.src="./src/fruit.png";
this.lan.src="./src/blue.png";
}
fruitObj.prototype.draw = function(){
for (var i = 0; i < this.num; i++) {
ctx2.drawImage(this.huang,this.x[i] - this.huang.width*0.5,this.y[i] - this.huang.height*0.5);
}
}
fruitObj.prototype.born = function(i){
var aneID =Math.floor( Math.random() * ane.num);
this.x = ane.x[aneID];
this.y = canHeight - ane.len[aneID];
}
2016-06-23
born方法中的代碼寫錯了:
this.x = ane.x[aneID];應(yīng)該是:this.x[i]=ane.x[aneID];
this.y = canHeight - ane.len[aneID];應(yīng)該是:this.y[i] = canHeight - ane.len[aneID];
坐標(biāo)x和y少寫了[i].
2016-07-08
我將ane寫在了全局區(qū)就可以了
2016-07-08
問下為什么報(bào)錯總是說我的ane沒有定義