0
0
Fork 0
mirror of https://github.com/liabru/matter-js.git synced 2025-01-11 16:00:48 -05:00

fix issues with render pixel ratio, closes #686, closes #687

This commit is contained in:
liabru 2018-11-17 23:43:24 +00:00
parent 773510f985
commit d57747785f
2 changed files with 12 additions and 5 deletions

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 = mouse.element.getAttribute('data-pixel-ratio') || 1;
mouse.pixelRatio = parseInt(mouse.element.getAttribute('data-pixel-ratio'), 10) || 1;
mouse.sourceEvents = {
mousemove: null,

View file

@ -155,7 +155,6 @@ var Mouse = require('../core/Mouse');
canvas.height = options.height * pixelRatio;
canvas.style.width = options.width + 'px';
canvas.style.height = options.height + 'px';
render.context.scale(pixelRatio, pixelRatio);
};
/**
@ -267,7 +266,11 @@ var Mouse = require('../core/Mouse');
boundsScaleX = boundsWidth / render.options.width,
boundsScaleY = boundsHeight / render.options.height;
render.context.scale(1 / boundsScaleX, 1 / boundsScaleY);
render.context.setTransform(
render.options.pixelRatio / boundsScaleX, 0, 0,
render.options.pixelRatio / boundsScaleY, 0, 0
);
render.context.translate(-render.bounds.min.x, -render.bounds.min.y);
};
@ -348,8 +351,8 @@ var Mouse = require('../core/Mouse');
// update mouse
if (render.mouse) {
Mouse.setScale(render.mouse, {
x: (render.bounds.max.x - render.bounds.min.x) / render.canvas.width,
y: (render.bounds.max.y - render.bounds.min.y) / render.canvas.height
x: (render.bounds.max.x - render.bounds.min.x) / render.options.width,
y: (render.bounds.max.y - render.bounds.min.y) / render.options.height
});
Mouse.setOffset(render.mouse, render.bounds.min);
@ -357,6 +360,10 @@ var Mouse = require('../core/Mouse');
} else {
constraints = allConstraints;
bodies = allBodies;
if (render.options.pixelRatio !== 1) {
render.context.setTransform(render.options.pixelRatio, 0, 0, render.options.pixelRatio, 0, 0);
}
}
if (!options.wireframes || (engine.enableSleeping && options.showSleeping)) {