From bf2451136f809798338f91c70be45ea2701fdbce Mon Sep 17 00:00:00 2001 From: Erik Onarheim Date: Sun, 18 Feb 2024 19:03:36 -0600 Subject: [PATCH] fix: screenToPageCoordinates should not offset by contentArea --- sandbox/tests/pointer/index.html | 4 ++-- sandbox/tests/pointer/pointer.ts | 15 ++++++++++++++- src/engine/Screen.ts | 4 +--- 3 files changed, 17 insertions(+), 6 deletions(-) diff --git a/sandbox/tests/pointer/index.html b/sandbox/tests/pointer/index.html index b824b2180..191c33101 100644 --- a/sandbox/tests/pointer/index.html +++ b/sandbox/tests/pointer/index.html @@ -6,12 +6,12 @@ Pointer diff --git a/sandbox/tests/pointer/pointer.ts b/sandbox/tests/pointer/pointer.ts index 826db611e..36ad46a91 100644 --- a/sandbox/tests/pointer/pointer.ts +++ b/sandbox/tests/pointer/pointer.ts @@ -66,10 +66,23 @@ var game2 = new Game2({ width: 600, height: 400, antialiasing: false, - displayMode: ex.DisplayMode.Fixed + displayMode: ex.DisplayMode.FitScreenAndFill }); game2.debug.collider.showBounds = true; game2.debug.graphics.showBounds = true; game2.toggleDebug(); +game2.input.pointers.primary.on('down', (evt) => { + const pos = game2.screen.worldToPageCoordinates(evt.worldPos); + const div = document.createElement('div'); + div.style.left = pos.x + 'px'; + div.style.top = pos.y + 'px'; + div.style.position = 'absolute'; + div.style.width = '100px'; + div.style.height = '100px'; + div.style.zIndex = '999'; + div.style.backgroundColor = 'black'; + document.body.appendChild(div); +}); + game2.initialize(); \ No newline at end of file diff --git a/src/engine/Screen.ts b/src/engine/Screen.ts index 97e84b72c..9383c6f07 100644 --- a/src/engine/Screen.ts +++ b/src/engine/Screen.ts @@ -628,9 +628,7 @@ export class Screen { let newX = point.x; let newY = point.y; - // offset by content area - newX = newX + this.contentArea.left; - newY = newY + this.contentArea.top; + // no need to offset by content area, drawing is already offset by this newX = (newX / this.resolution.width) * this.viewport.width; newY = (newY / this.resolution.height) * this.viewport.height;