慕粉3744539
2016-10-07 11:57
// JavaScript Document
var monObj=function(){
this.x;
this.y;
this.angle;
this.bigEye=new Image();
this.bigBody=new Image();
this.bigTail=new Image();
}
monObj.prototype.init=function(){
this.x=canWidth*0.5;
this.y=canHeight*0.5;
this.angle=0;
this.bigEye.src="./image/bigEye0.png";
this.bigBody.src="./image/bigSwim0.png";
this.bigTail.src="./image/bigTail0.png";
}
monObj.prototype.draw=function(){
//lerp x,y
this.x=lerpDistance(mx,this.x,0.98);
this.y=lerpDistance(my,this.y,0.98);
//angle
var deltaY=my-this.y;
var deltaX=mx-this.x;
var beta=Math.atan2(deltaY,deltaX);
//lerp angle鼠标角度
this.angle=lerpAngle(beta,this.angle,0.6);
ctx1.save();
ctx1.translate(this.x,this.y);
ctx1.rotate(this.angle);//旋转画布
ctx1.drawImage(this.bigEye,-this.bigEye.width*0.5,-this.bigEye.height*0.5);
ctx1.drawImage(this.bigBody,-this.bigBody.width*0.5,-this.bigBody.height*0.5);
ctx1.drawImage(this.bigTail,-this.bigTail*0.5+30,-this.bigTail.height*0.5);
ctx1.restore();
}
ctx1.drawImage(this.bigTail,-this.bigTail.width*0.5+30,-this.bigTail.height*0.5);
你丢了 获取宽度 的 值了“width”。
你会绘制大鱼 的顺序最好也调整一下 尾巴 , 身体, 眼睛
仅供参考!!!!!!
好好 检查一下 代码
HTML5小游戏---爱心鱼(下)
46272 学习 · 189 问题
相似问题