• 手机版

    扫码体验手机版

  • 微信公众号

    扫码关注公众号

国内首家协议开发

软芯音视解码保护平台

在线
客服

发布
需求

在线
聊天

天盟
APP

天盟APP下载

关注
微信

微信扫一扫访问
顶部

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

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

免责声明:本内容仅代表回答会员见解不代表天盟观点,请谨慎对待。

版权声明:作者保留权利,不代表天盟立场。

使用道具 举报

全部参与3

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

使用道具 举报

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

使用道具 举报

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);
        }
}

使用道具 举报

发新帖

发布任务需求已有1031167位用户正在使用天盟网服务

发布分类: *
任务预算: *
需求内容: *
手机号码: *
任务商家报价为
  • 预算价 :
  • 成交价 :
  • 完工期 :
  • 质保期 :

* 最终任务项目以服务商报价、双方协商为准!