Issue #5: Mouse handling — zoom-to-mouse + middle-click pan #10
@@ -57,12 +57,9 @@ export class CameraSystem {
|
|||||||
d: kb.addKey(Phaser.Input.Keyboard.KeyCodes.D),
|
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 = this.scene.add.graphics()
|
||||||
this.debugCross.setDepth(999)
|
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
|
// Track mouse world position on every move so we have a stable value for zoom
|
||||||
this.scene.input.on('pointermove', (ptr: Phaser.Input.Pointer) => {
|
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.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)
|
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) {
|
if (this.debugCross) {
|
||||||
this.debugCross.setPosition(
|
const cx = cam.scrollX + cam.width / (2 * cam.zoom)
|
||||||
cam.scrollX + cam.width / (2 * cam.zoom),
|
const cy = cam.scrollY + cam.height / (2 * cam.zoom)
|
||||||
cam.scrollY + cam.height / (2 * cam.zoom),
|
const arm = 12 / cam.zoom // 12 screen pixels at any zoom
|
||||||
)
|
this.debugCross.clear()
|
||||||
this.debugCross.setScale(1 / cam.zoom)
|
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"
|
// Periodically save camera center as "player position"
|
||||||
|
|||||||
Reference in New Issue
Block a user