果實不顯示
有人幫我看下嗎?果實不顯示
?var fruitObj = function()
?{
? this.alive = []; //bool
? 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
? if (this.l[i] <= 14) {
? this.l[i] += 0.01 * deltaTime; //保證游戲動作的流暢與連貫
? }
? else{
? this.y[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); //??鴺?biāo)
? this.x[i] = ane.x[aneID]; ? ? ? ?//果實的x坐標(biāo)
? this.y[i] = canHeight - ane.len[aneID]; ? ?////果實的y坐標(biāo)
? ? this.l[i] = 0;
?}
2017-06-11
你再去看一下main.js這個文件,你的deltaTime這個變量是不是沒有初始化,這個代碼的問題就是你在deltaTime還沒有初始化的時候就用了這個變量
2017-06-03
我測試過了,問題出在this.l[i]+=0.01*deltaTime;這句代碼上,經(jīng)過這句代碼之后this.l[i]變成了NaN