🐛 zoom-to-mouse: ptr.worldX/Y formula, debug log still active

This commit is contained in:
2026-03-20 20:37:11 +00:00
parent 0e4c7c96ee
commit fb4abb7256

View File

@@ -62,13 +62,16 @@ export class CameraSystem {
this.debugCross.lineBetween(cx - 12, cy, cx + 12, cy) this.debugCross.lineBetween(cx - 12, cy, cx + 12, cy)
this.debugCross.lineBetween(cx, cy - 12, cx, cy + 12) 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) => { 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) 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.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 centerX = cam.scrollX + cam.width / (2 * cam.zoom)
const centerY = cam.scrollY + cam.height / (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 // Middle-click pan: start on button down