【问题标题】:Trying to rotate image in direction of mouse pointer on JavaScript canvas?试图在 JavaScript 画布上沿鼠标指针方向旋转图像?
【发布时间】:2016-11-10 00:01:58
【问题描述】:

这是我的代码:

   socket.on('newPositions', function(data) {
     ctx.clearRect(0, 0, 1500, 1000);
     for (var i = 0; i < data.length; i++) {
       var img = document.getElementById("player");
       var rotation = -(Math.atan2(data[i].x - event.clientX, data[i].y - event.clientY) * 180 / Math.PI);
       //ctx.drawImage(img, data[i].x, data[i].y, 89, 275);
       ctx.save();
       ctx.translate(data[i].x + 89 / 2, data[i].y + 275 / 2);
       ctx.rotate(rotation);
       ctx.translate(-data[i].x + 89 / 2, -data[i].y + 275 / 2);
       ctx.drawImage(img, data[i].x, data[i].y);
       ctx.restore();
     }
   });

如果有人可以帮助我找到解决方法,我将不胜感激,因为我现在不知道出了什么问题 :)

【问题讨论】:

    标签: javascript node.js image canvas rotation


    【解决方案1】:

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-10-14
      • 2021-09-27
      • 2013-04-14
      • 1970-01-01
      • 2011-07-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多