🐛 fix debug cross: world-space position + counter-scale, tracks viewport center correctly

This commit is contained in:
2026-03-20 20:57:46 +00:00
parent 6de4c1cbb9
commit 6fa3ae4465

View File

@@ -57,14 +57,12 @@ export class CameraSystem {
d: kb.addKey(Phaser.Input.Keyboard.KeyCodes.D), 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 = this.scene.add.graphics()
this.debugCross.setScrollFactor(0).setDepth(999) this.debugCross.setDepth(999)
this.debugCross.lineStyle(2, 0xff0000, 1) this.debugCross.lineStyle(2, 0xff0000, 1)
const cx = cam.width / 2 this.debugCross.lineBetween(-12, 0, 12, 0)
const cy = cam.height / 2 this.debugCross.lineBetween(0, -12, 0, 12)
this.debugCross.lineBetween(cx - 12, cy, cx + 12, cy)
this.debugCross.lineBetween(cx, cy - 12, cx, cy + 12)
// Track mouse world position on every move so we have a stable value for zoom // Track mouse world position on every move so we have a stable value for zoom
this.scene.input.on('pointermove', (ptr: Phaser.Input.Pointer) => { 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.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) 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" // Periodically save camera center as "player position"
this.saveTimer += delta this.saveTimer += delta
if (this.saveTimer >= this.SAVE_TICK) { if (this.saveTimer >= this.SAVE_TICK) {