为了账号安全,请及时绑定邮箱和手机立即绑定

绘制小鱼身体动画时出错,导致前面绘制的都出不来了

var babyObj = function()

{

this.x;

this.y;

this.angle;


this.babyTailTimer = 0;

this.babyTailCount = 0;


this.babyEyeTimer = 0;

this.babyEyeCount = 0;

this.babyEyeInterval = 1000;


this.babyBodeTimer = 0;

this.babyBodeCount = 0;

babyObj.prototype.init = function()

{

this.x=canWidth*0.5 - 50;

this.y=canHeight*0.5 + 50;

this.angle=0;

}

babyObj.prototype.draw = function()

{

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

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


var deltaY=mom.y-this.y;

var deltaX=mom.x-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==0)

{

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

}else

{

this.babyEyeInterval=200;

}

}

this.babyBodeTimer += deltaTime;

if(this.babyBodeTimer > 300)

{

this.babyBodeCount = this.babyBodeCount+1;

this.babyBodeTimer%=300;

if(this.babyBodeCount>19)

{

this.babyBodeCount = 19; 

}

}



ctx1.save();

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

ctx1.rotate(this.angle);


var babyTailCount = this.babyTailCount;

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

var babyBodeCount = this.babyBodeCount;

ctx1.drawImage(babyBode[babyBodeCount],-babyBode[babyBodeCount].width * 0.5,-babyBode[babyBodeCount].height *0.5);

var babyEyeCount = this.babyEyeCount;

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

ctx1.restore();

}

http://img1.sycdn.imooc.com//5770adeb0001626719201080.jpg

正在回答

1 回答

还没有敲代码测试,

0 回复 有任何疑惑可以回复我~
#1

qazzxc3549823 提问者

非常感谢!
2016-06-28 回复 有任何疑惑可以回复我~
#2

慕UI1547199 回复 qazzxc3549823 提问者

我也是这样,怎么敲测试代码
2016-12-05 回复 有任何疑惑可以回复我~

举报

0/150
提交
取消
HTML5小游戏---爱心鱼(下)
  • 参与学习       46272    人
  • 解答问题       189    个

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

进入课程

绘制小鱼身体动画时出错,导致前面绘制的都出不来了

我要回答 关注问题
意见反馈 帮助中心 APP下载
官方微信