大鱼没有跟上鼠标动

来源:2-8 大鱼随鼠标移动

慕函数6109166

2016-08-17 10:28

鼠标一进入界面 大鱼就想左上角移动,固定在左上角了  求大神指教下

代码如下:

// JavaScript Document

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.99);

this.y = lerpDistance(my, this.y, 0.99);

//delta angle

//Math.atan2(y,x)

var deltaY = my - this.y;

var deltaX = mx - this.x;

var beta = Math.atan2(deltaY,deltaX);//-PI, 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();

}


写回答 关注

2回答

  • 慕粉3591791
    2016-08-18 21:22:44
    已采纳

    commonFunction.js在html中引进来了没有?

  • 慕函数6109166
    2016-08-23 15:56:32

    谢谢 已经好了

    慕粉3451...

    怎么解决的?

    2016-10-22 11:26:25

    共 1 条回复 >

HTML5小游戏---爱心鱼(上)

学做HTML5游戏,轻轻松松带你上手,适合刚入手游戏开发的同学

92350 学习 · 551 问题

查看课程

相似问题