From 2b60b6e9eded680ec1d83c440c4e7347114cdfe7 Mon Sep 17 00:00:00 2001 From: Atlaskor Date: Thu, 13 Nov 2025 17:02:50 +0000 Subject: [PATCH] Update server/static/main.js --- server/static/main.js | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/server/static/main.js b/server/static/main.js index caecbe7..211763b 100644 --- a/server/static/main.js +++ b/server/static/main.js @@ -82,6 +82,24 @@ class GameScene extends Phaser.Scene { } update(time, delta) { this.mapView.update(delta); + // --- NEW: sync our actual current position to the server --- + if (!this._lastPosSyncTime) this._lastPosSyncTime = 0; + if (!this._lastPos) this._lastPos = { x: 0, y: 0 }; + + const pos = this.mapView.getPlayerPosition(); + const dist = Phaser.Math.Distance.Between( + pos.x, + pos.y, + this._lastPos.x, + this._lastPos.y + ); + + // Only spam server if we moved enough or it’s been a bit + 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 }; + this._lastPosSyncTime = time; + } } }