🐛 fix debug cross: world-space position + counter-scale, tracks viewport center correctly
This commit is contained in:
@@ -57,14 +57,12 @@ export class CameraSystem {
|
||||
d: kb.addKey(Phaser.Input.Keyboard.KeyCodes.D),
|
||||
}
|
||||
|
||||
// Debug cross at viewport center (fixed to screen, not world)
|
||||
// Debug cross — positioned in world space at viewport center, updated each frame
|
||||
this.debugCross = this.scene.add.graphics()
|
||||
this.debugCross.setScrollFactor(0).setDepth(999)
|
||||
this.debugCross.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)
|
||||
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
|
||||
this.scene.input.on('pointermove', (ptr: Phaser.Input.Pointer) => {
|
||||
@@ -136,6 +134,15 @@ export class CameraSystem {
|
||||
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)
|
||||
|
||||
// Keep debug cross at viewport center in world space, counter-scale so it stays 1px
|
||||
if (this.debugCross) {
|
||||
this.debugCross.setPosition(
|
||||
cam.scrollX + cam.width / (2 * cam.zoom),
|
||||
cam.scrollY + cam.height / (2 * cam.zoom),
|
||||
)
|
||||
this.debugCross.setScale(1 / cam.zoom)
|
||||
}
|
||||
|
||||
// Periodically save camera center as "player position"
|
||||
this.saveTimer += delta
|
||||
if (this.saveTimer >= this.SAVE_TICK) {
|
||||
|
||||
Reference in New Issue
Block a user