html canvas windowToCanvas(canvas,x,y)实现

时间:2018-08-31 02:52:02

标签: canvas html5-canvas

在本书Core HTML5 Canvas: Graphics, Animation, and Game Development中,我发现作者将 windowToCanvas 实现为

function windowToCanvas(canvas, x, y) {
   var bbox = canvas.getBoundingClientRect();

   return { x: x - bbox.left * (canvas.width  / bbox.width),
            y: y - bbox.top  * (canvas.height / bbox.height)
          };
}

但我确实认为它应该返回:

          { x: (x - bbox.left) * (canvas.width  / bbox.width),
            y: (y - bbox.top)  * (canvas.height / bbox.height)
          };

我对吗?

您可以自由查看here章。在示例1.6

0 个答案:

没有答案