为了账号安全,请及时绑定邮箱和手机立即绑定

为什么我的鱼妈妈不是跟着鼠标移动,而是鼠标点击一点就移动。

为什么我的鱼妈妈不是跟着鼠标移动,而是鼠标点击一点就移动。

嘴角残留smile 2016-09-08 09:08:19
为什么我的鱼妈妈不是跟着鼠标移动,而是鼠标点击一点就移动。
查看完整描述

3 回答

?
轻键快码

TA贡献5条经验 获得超2个赞

真当网友都是代码解析器啊。

查看完整回答
1 反对 回复 2016-09-08
?
业余奶茶品鉴师

TA贡献260条经验 获得超388个赞

最好可以把代码粘出来,不然看不出问题。应该是时间不对,写了点击事件。

望采纳

查看完整回答
1 反对 回复 2016-09-08
?
嘴角残留smile

TA贡献1条经验 获得超0个赞

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()

{

this.x = lerpDistance(mx, this.x, 0.99);

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


var deltaY = my - this.y;

var deltaX = mx - this.x;

var beta = Math.atan2(deltaY, deltaX)+ Math.PI;


this.angle = lerpAngle(beta, this.angle, 0.6);


ctx2.save();

ctx2.translate(this.x, this.y);

ctx2.rotate(this.angle);

ctx2.drawImage(this.bigEye, -this.bigEye.width * 0.5, -this.bigEye.height * 0.5);

ctx2.drawImage(this.bigBody, -this.bigBody.width * 0.5, -this.bigBody.height * 0.5);

ctx2.drawImage(this.bigTail, -this.bigTail.width * 0.5 + 30, -this.bigTail.height * 0.5);


ctx2.restore();


}

main.js



var can1;

var can2;


var ctx1;

var ctx2;


var canWidth;

var canHeight;


var lastTime;

var detaTime;


var bgPic = new Image();


var ane;

var fruit;

var mom;


var mx;

var my;



document.body.onload = game;

function game()

{

init();

lastTime = Date.now();

detaTime = 0;

gameloop();

}

function init()

{

//获得canvas context

can1 = document.getElementById("canvas1");//fishes,dust,ui,circle

ctx1 = can1.getContext('2d');

can2 = document.getElementById("canvas2");//background,ane ,fruits

ctx2 = can2.getContext('2d');


can2.addEventListener('mousemove',onMouseMove, false);


bgPic.src = "./src/background.jpg";


canWidth = can1.width;

canHeight = canvas1.height;


ane = new aneObj();

ane.init();


fruit = new fruitObj();

fruit.init();


mom = new momObj();

mom.init();


mx = canWidth * 0.5;

my = canHeight * 0.5;


}

function gameloop()

{

window.requestAnimFrame(gameloop);

var now = Date.now();

detaTime = now - lastTime;

lastTime = now;


drawBackground();

ane.draw();

fruitMonitor();

fruit.draw();


ctx1.clearRect(0, 0, canWidth, canHeight);

mom.draw();

}

function onMouseMove(e)

{

if(e.offSetX || e.layerX)

{

mx = e.offSetX == undefined ? e.layerX : e.offSetX;

my = e.offSetY == undefined ? e.layerY : e.offSetY;

//console.log(mx);

}

}


查看完整回答
反对 回复 2016-09-08
  • 3 回答
  • 0 关注
  • 1295 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信