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 0e4c7c96ee - Show all commits

View File

@@ -26,6 +26,7 @@ export class CameraSystem {
private middlePanActive = false
private lastPanX = 0
private lastPanY = 0
private debugCross?: Phaser.GameObjects.Graphics
constructor(scene: Phaser.Scene, adapter: LocalAdapter) {
this.scene = scene
@@ -52,10 +53,22 @@ export class CameraSystem {
d: kb.addKey(Phaser.Input.Keyboard.KeyCodes.D),
}
// Debug cross at viewport center (fixed to screen, not world)
this.debugCross = this.scene.add.graphics()
this.debugCross.setScrollFactor(0).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)
// Scroll wheel zoom
this.scene.input.on('wheel', (_ptr: Phaser.Input.Pointer, _objs: unknown, _dx: number, dy: number) => {
this.scene.input.on('wheel', (ptr: Phaser.Input.Pointer, _objs: unknown, _dx: number, dy: number) => {
const newZoom = Phaser.Math.Clamp(cam.zoom - Math.sign(dy) * ZOOM_STEP, MIN_ZOOM, MAX_ZOOM)
cam.setZoom(newZoom)
const centerX = cam.scrollX + cam.width / (2 * cam.zoom)
const centerY = cam.scrollY + cam.height / (2 * cam.zoom)
console.log(`[zoom] ptr.x=${ptr.x.toFixed(0)} ptr.y=${ptr.y.toFixed(0)} | ptr.worldX=${ptr.worldX.toFixed(0)} ptr.worldY=${ptr.worldY.toFixed(0)} | center=(${centerX.toFixed(0)}, ${centerY.toFixed(0)}) zoom=${cam.zoom.toFixed(2)}`)
})
// Middle-click pan: start on button down