我从https://github.com/sethladd/bad-aliens-dart/blob/master/web/Game.dart找到了以下代码:
ClientRect rect = ctx.canvas.getBoundingClientRect();
clientBoundingRect = new GamePoint(rect.left, rect.top);
...
GamePoint getXandY(e) {
num x = e.clientX - clientBoundingRect.x - (ctx.canvas.width/2);
num y = e.clientY - clientBoundingRect.y - (ctx.canvas.height/2);
return new GamePoint(x, y);
}
我已经测试过,但它没有计算出画布中正确的鼠标位置。