鱼太大了,而且鱼总不能停在鼠标停的地方,只有鼠标在浏览器左上角鱼才能和鼠标重合,鼠标离左上角越远鱼就离鼠标越远
main.js里面和鼠标相关的:
can1.addEventListener('mousemove', onMouseMove, false);
function onMouseMove(e)
{
if(e.offsetX || e.layerX)
{
mx = e.offsetX == undefined ? e.layerX : e.offsetX;
my = e.offsetY == undefined ? e.layerY : e.offsetY;
}
}
mom.js里面:
momObj.prototype.draw = function()
{
this.x = lerpDistance(mx, this.x, 0.98);
this.y = lerpDistance(my, this.y, 0.98);
var deltaY = my - this.y;
var deltaX = mx - this.x;
var beta = Math.atan2(deltaY, deltaX);
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.width * 0.5 + 30, -this.bigTail.height * 0.5);
ctx1.restore();
}