Issue #5: Mouse handling — zoom-to-mouse + middle-click pan #10

Merged
tekki merged 21 commits from feature/mouse-handling into master 2026-03-21 14:06:45 +00:00
Showing only changes of commit 0011bc9877 - Show all commits

View File

@@ -57,12 +57,9 @@ export class CameraSystem {
d: kb.addKey(Phaser.Input.Keyboard.KeyCodes.D),
}
// Debug cross — positioned in world space at viewport center, updated each frame
// Debug cross — redrawn every frame in world space, no transforms needed
this.debugCross = this.scene.add.graphics()
this.debugCross.setDepth(999)
this.debugCross.lineStyle(2, 0xff0000, 1)
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) => {
@@ -134,13 +131,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
// Redraw debug cross every frame at viewport center in world space
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)
const cx = cam.scrollX + cam.width / (2 * cam.zoom)
const cy = cam.scrollY + cam.height / (2 * cam.zoom)
const arm = 12 / cam.zoom // 12 screen pixels at any zoom
this.debugCross.clear()
this.debugCross.lineStyle(2 / cam.zoom, 0xff0000, 1)
this.debugCross.lineBetween(cx - arm, cy, cx + arm, cy)
this.debugCross.lineBetween(cx, cy - arm, cx, cy + arm)
}
// Periodically save camera center as "player position"