问答详情
源自:2-5 果实绘制(果实上浮)

为什么果实往上走了,但是还会有线条

fruitObj.prototype.draw=function () {
    for(var i=0;i<this.num;i++){
    //    draw
    //    find a ane,grow,fly up
        if(this.l[i]<=14){
            this.l[i]+=0.01*daltaTime;
        }
        else{
            this.y[i]-=0.07*daltaTime
        }
        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])
    }
}
//果实状态,允许15个
fruitObj.prototype.update=function () {
    var num=0;
    for(var i=0;i<num;i++){
        if(this.alive[i]){
            num++
        }
    }
}
fruitObj.prototype.born=function (i) {
//    找到坐标
//    问题:不用取整,无法获得ID
    var aneId=Math.floor(Math.random()*ane.num);
    this.x[i]=ane.x[aneId];
    this.y[i]=canHeight-ane.y[aneId]
    this.l[i]=0;
}


提问者:慕哥0728771 2018-07-07 11:12

个回答

  • 前端工程师666777888
    2018-08-26 16:52:10

    fruitObj.prototype.draw=function () { 
    ctx2.clearRect(0,0,canWidth,canHeight);//加上这句就行了
    for(var i=0;i<this.num;i++){
        //    draw
        //    find a ane,grow,fly up
            if(this.l[i]<=14){
                this.l[i]+=0.01*daltaTime;
            }
            else{
                this.y[i]-=0.07*daltaTime
            }
            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])
        }
        }