From 6fa3ae4465808cb33286dde98375221324c63d18 Mon Sep 17 00:00:00 2001 From: tekki mariani Date: Fri, 20 Mar 2026 20:57:46 +0000 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20fix=20debug=20cross:=20world-spa?= =?UTF-8?q?ce=20position=20+=20counter-scale,=20tracks=20viewport=20center?= =?UTF-8?q?=20correctly?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/systems/CameraSystem.ts | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/src/systems/CameraSystem.ts b/src/systems/CameraSystem.ts index 7d507fd..68018c8 100644 --- a/src/systems/CameraSystem.ts +++ b/src/systems/CameraSystem.ts @@ -57,14 +57,12 @@ export class CameraSystem { d: kb.addKey(Phaser.Input.Keyboard.KeyCodes.D), } - // Debug cross at viewport center (fixed to screen, not world) + // Debug cross — positioned in world space at viewport center, updated each frame this.debugCross = this.scene.add.graphics() - this.debugCross.setScrollFactor(0).setDepth(999) + this.debugCross.setDepth(999) this.debugCross.lineStyle(2, 0xff0000, 1) - const cx = cam.width / 2 - const cy = cam.height / 2 - this.debugCross.lineBetween(cx - 12, cy, cx + 12, cy) - this.debugCross.lineBetween(cx, cy - 12, cx, cy + 12) + this.debugCross.lineBetween(-12, 0, 12, 0) + this.debugCross.lineBetween(0, -12, 0, 12) // Track mouse world position on every move so we have a stable value for zoom this.scene.input.on('pointermove', (ptr: Phaser.Input.Pointer) => { @@ -136,6 +134,15 @@ export class CameraSystem { cam.scrollX = Phaser.Math.Clamp(cam.scrollX + dx, 0, worldW - cam.width / cam.zoom) cam.scrollY = Phaser.Math.Clamp(cam.scrollY + dy, 0, worldH - cam.height / cam.zoom) + // Keep debug cross at viewport center in world space, counter-scale so it stays 1px + if (this.debugCross) { + this.debugCross.setPosition( + cam.scrollX + cam.width / (2 * cam.zoom), + cam.scrollY + cam.height / (2 * cam.zoom), + ) + this.debugCross.setScale(1 / cam.zoom) + } + // Periodically save camera center as "player position" this.saveTimer += delta if (this.saveTimer >= this.SAVE_TICK) {