鱼的方向不对,总是鱼尾巴跟着鼠标移动的方向走
来源:2-8 大鱼随鼠标移动
慕粉3354867
2016-06-29 22:22
this.x = lerpDistance(mx, this.x, 0.9);
this.y = lerpDistance(my, this.y, 0.9);
var deltaY = my - this.y;
var deltaX = mx - this.x;
var beta = Math.atan2(deltaY,deltaX);
this.angle = lerpAngle(beta, this.angle, 0.9);
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();
写回答
关注