MCPcopy Create free account
hub / github.com/melonjs/melonJS / globalToLocal

Function globalToLocal

packages/melonjs/src/input/pointerevent.ts:607–619  ·  view source on GitHub ↗
(x: number, y: number, v?: Vector2d)

Source from the content-addressed store, hash-verified

605 * };
606 */
607export function globalToLocal(x: number, y: number, v?: Vector2d): Vector2d {
608 v = v || vector2dPool.get();
609 const rect = device.getElementBounds(_app.renderer.getCanvas());
610 const pixelRatio = globalThis.devicePixelRatio || 1;
611 x -= rect.left + (globalThis.pageXOffset || 0);
612 y -= rect.top + (globalThis.pageYOffset || 0);
613 const scale = _app.renderer.scaleRatio;
614 if (scale.x !== 1.0 || scale.y !== 1.0) {
615 x /= scale.x;
616 y /= scale.y;
617 }
618 return v.set(x * pixelRatio, y * pixelRatio);
619}
620
621/**
622 * enable/disable all gestures on the given element.<br>

Callers 1

setEventMethod · 0.90

Calls 3

getCanvasMethod · 0.80
getMethod · 0.65
setMethod · 0.45

Tested by

no test coverage detected