问答详情
源自:2-4 果实绘制(静态果实)

我的果实也没出来

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];

}


提问者:qq_我在呢_0 2016-06-21 16:49

个回答

  • java家洼
    2016-06-23 16:03:03
    已采纳

    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].


  • moonstar
    2016-07-08 15:44:49

    我将ane写在了全局区就可以了

  • moonstar
    2016-07-08 15:20:29

    问下为什么报错总是说我的ane没有定义