0
0
Fork 0
mirror of https://github.com/liabru/matter-js.git synced 2025-01-31 18:14:55 -05:00

fix Mouse inaccuracy when pixelRatio is not int

This commit is contained in:
action-script 2021-10-14 07:12:49 +02:00
parent e909b0466c
commit 968b8b5735

View file

@ -34,7 +34,7 @@ var Common = require('../core/Common');
mouse.scale = { x: 1, y: 1 };
mouse.wheelDelta = 0;
mouse.button = -1;
mouse.pixelRatio = parseInt(mouse.element.getAttribute('data-pixel-ratio'), 10) || 1;
mouse.pixelRatio = mouse.element.getAttribute('data-pixel-ratio') || 1;
mouse.sourceEvents = {
mousemove: null,
@ -193,8 +193,12 @@ var Common = require('../core/Common');
}
return {
x: x / (element.clientWidth / (element.width || element.clientWidth) * pixelRatio),
y: y / (element.clientHeight / (element.height || element.clientHeight) * pixelRatio)
x: parseInt(
x / (element.clientWidth / (element.width || element.clientWidth) * pixelRatio)
, 10),
y: parseInt(
y / (element.clientHeight / (element.height || element.clientHeight) * pixelRatio)
, 10)
};
};