中午晚上吃啥
2015-12-08 10:36
鱼不跟随鼠标动 而且鱼也不在屏幕中间 跟视频上一样的代码 没有报错 不知道怎么解决
var momObj = function(){
this.x;
this.y;
this.angle;
this.bigEye = new Image();
this.bigBody = new Image();
this.bigTail = new Image();
}
momObj.prototype.init = function(){
this.x = canWidth*0.5;
this.y = canHeight*0.5;
this.angle = 0;
this.bigEye.src = "./src/bigEye0.png";
this.bigBody.src = "./src/bigSwim0.png";
this.bigTail.src = "./src/bigTail0.png";
}
momObj.prototype.draw = function(){
//lerp x,y
this.x = lerpDistance(mx,this.x,0.98);
this.y = lerpDistance(my,this.y,0.98);
//delta angle
//Math.atan2(y,x)
var deltaY = my-this.y;
var deltaX = mx-this.x;
var beta = Math.atan2(deltaY,deltaX)+Math.PI;
//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.bigTail,-this.bigTail.width*0.5+30,-this.bigTail.height*0.5);
ctx1.drawImage(this.bigBody,-this.bigBody.width*0.5,-this.bigBody.height*0.5);
ctx1.drawImage(this.bigEye,-this.bigEye.width*0.5,-this.bigEye.height*0.5);
ctx1.restore();
}
你好,把代码贴出来看看。
HTML5小游戏---爱心鱼(上)
92348 学习 · 551 问题
相似问题