diff --git a/server/static/main.js b/server/static/main.js index 211763b..94bf6eb 100644 --- a/server/static/main.js +++ b/server/static/main.js @@ -80,13 +80,19 @@ class GameScene extends Phaser.Scene { // HUD zoom hook window.setGameZoom = z => this.mapView.setZoom(z); } - update(time, delta) { - this.mapView.update(delta); - // --- NEW: sync our actual current position to the server --- + update(time, delta) { + // Move local player + if (this.mapView) { + this.mapView.update(delta); + } + + // --- sync true current position to server --- if (!this._lastPosSyncTime) this._lastPosSyncTime = 0; if (!this._lastPos) this._lastPos = { x: 0, y: 0 }; - const pos = this.mapView.getPlayerPosition(); + const pos = this.mapView?.getPlayerPosition?.(); + if (!pos) return; + const dist = Phaser.Math.Distance.Between( pos.x, pos.y, @@ -94,7 +100,7 @@ class GameScene extends Phaser.Scene { this._lastPos.y ); - // Only spam server if we moved enough or it’s been a bit + // Only send if we moved enough or some time has passed if (dist > 8 || time - this._lastPosSyncTime > 250) { socket.emit('pos:update', { x: pos.x, y: pos.y }); this._lastPos = { x: pos.x, y: pos.y };