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 fb4abb7256 - Show all commits

View File

@@ -62,13 +62,16 @@ export class CameraSystem {
this.debugCross.lineBetween(cx - 12, cy, cx + 12, cy)
this.debugCross.lineBetween(cx, cy - 12, cx, cy + 12)
// Scroll wheel zoom
// Scroll wheel zoom — zoom toward mouse pointer
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)
if (newZoom === cam.zoom) return
cam.setZoom(newZoom)
cam.scrollX = ptr.worldX - ptr.x / newZoom
cam.scrollY = ptr.worldY - ptr.y / 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)}`)
console.log(`[zoom] ptr=(${ptr.x.toFixed(0)},${ptr.y.toFixed(0)}) world=(${ptr.worldX.toFixed(0)},${ptr.worldY.toFixed(0)}) center=(${centerX.toFixed(0)},${centerY.toFixed(0)}) zoom=${cam.zoom.toFixed(2)}`)
})
// Middle-click pan: start on button down