Cannot read property 'width' of undefined

来源:1-3 眨眼睛

独一无

2015-11-02 22:54

var babyObj=function(){

this.x;

this.y;

this.angle;

this.babyEye=new Image();

this.babyBody=new Image();

this.babyTail=new Image();

this.babyTailTimer=0;

this.babyTailCount=0;

this.babyEyeTimer=0;

this.babyEyeCount=0;

this.babyEyeInterval=1000;

}


babyObj.prototype.init=function(){

this.x=canWidth*0.5-50;

this.y=canHeight*0.5+50;

    this.angle=0;

this.babyBody.src="./src/babyFade0.png";

}


babyObj.prototype.draw=function(){

this.x=lerpDistance(mom.x, this.x, 0.9);

this.y=lerpDistance(mom.y, this.y, 0.9);

var deltaY=mom.y-this.y;

var deltaX=mom.y-this.x;

var beta=Math.atan2(deltaY,deltaX)+Math.PI;

this.angle=lerpAngle(beta, this.angle, 0.6);

this.babyTailTimer+=deltaTime;

if(this.babyTailTimer>50){

this.babyTailCount=(this.babyTailCount+1)%8;

this.babyTailTimer%=50;

}

this.babyEyeTimer+=deltaTime;

if(this.babyEyeTimer>this.babyEyeInterval){

this.babyEyeCount=(this.babyEyeCount+1)%2;

this.babyEyeTimer%=this.babyEyeInterval;

if(this.babyEyeCount==1){

this.babyEyeInterval=Math.random()*1500+2000;

}else{

this.babyEyeInterval=200;

}

}

ctx1.save();

ctx1.translate(this.x,this.y);

ctx1.rotate(this.angle);

var babyTailCount=this.babyTailCount;

var babyEyeCount=this.babyEyeCount;

ctx1.drawImage(babyTail[babyTailCount],-babyTail[babyTailCount].width*0.5+25,-babyTail[babyTailCount].height*0.5);

ctx1.drawImage(this.babyBody,-this.babyBody.width*0.5,-this.babyBody.height*0.5);

ctx1.drawImage(babyEye[babyEyeCount],-babyEye[babyEyeCount].width*0.5,-babyEye[babyEyeCount].height*0.5);

ctx1.restore();

}


写回答 关注

2回答

  • 陆慢慢
    2016-01-05 16:42:32

    我是因为mom.x没有赋初值

  • qq_痞子陈_0
    2015-12-15 11:15:13

    把width后面的括号去掉就可以了

    陆慢慢

    哪里有括号?

    2016-01-05 16:22:35

    共 1 条回复 >

HTML5小游戏---爱心鱼(下)

通过一个清新美好的小游戏教程,熟悉游戏开发流程

46272 学习 · 189 问题

查看课程

相似问题