🐛 debug: log mouse+center on zoom, draw red cross at viewport center
This commit is contained in:
@@ -26,6 +26,7 @@ export class CameraSystem {
|
|||||||
private middlePanActive = false
|
private middlePanActive = false
|
||||||
private lastPanX = 0
|
private lastPanX = 0
|
||||||
private lastPanY = 0
|
private lastPanY = 0
|
||||||
|
private debugCross?: Phaser.GameObjects.Graphics
|
||||||
|
|
||||||
constructor(scene: Phaser.Scene, adapter: LocalAdapter) {
|
constructor(scene: Phaser.Scene, adapter: LocalAdapter) {
|
||||||
this.scene = scene
|
this.scene = scene
|
||||||
@@ -52,10 +53,22 @@ 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)
|
||||||
|
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
|
// 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)
|
const newZoom = Phaser.Math.Clamp(cam.zoom - Math.sign(dy) * ZOOM_STEP, MIN_ZOOM, MAX_ZOOM)
|
||||||
cam.setZoom(newZoom)
|
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
|
// Middle-click pan: start on button down
|
||||||
|
|||||||
Reference in New Issue
Block a user