diff --git a/server/static/main.js b/server/static/main.js index 94bf6eb..08a952f 100644 --- a/server/static/main.js +++ b/server/static/main.js @@ -81,29 +81,32 @@ class GameScene extends Phaser.Scene { window.setGameZoom = z => this.mapView.setZoom(z); } update(time, delta) { - // Move local player + // Let MapView handle movement if (this.mapView) { this.mapView.update(delta); + } else { + return; } + // Get the actual player sprite from MapView + const player = this.mapView.player; + if (!player) return; + // --- 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?.(); - if (!pos) return; + if (!this._lastPos) this._lastPos = { x: player.x, y: player.y }; const dist = Phaser.Math.Distance.Between( - pos.x, - pos.y, + player.x, + player.y, this._lastPos.x, this._lastPos.y ); // 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 }; + socket.emit('pos:update', { x: player.x, y: player.y }); + this._lastPos = { x: player.x, y: player.y }; this._lastPosSyncTime = time; } }