qq_我在呢_0
2016-06-21 16:49
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];
}
born方法中的代码写错了:
this.x = ane.x[aneID];应该是:this.x[i]=ane.x[aneID];
this.y = canHeight - ane.len[aneID];应该是:this.y[i] = canHeight - ane.len[aneID];
坐标x和y少写了[i].
我将ane写在了全局区就可以了
问下为什么报错总是说我的ane没有定义
HTML5小游戏---爱心鱼(上)
92350 学习 · 551 问题
相似问题