Update server/static/main.js

This commit is contained in:
2025-11-13 17:02:50 +00:00
parent 48149bb17b
commit 2b60b6e9ed

View File

@@ -82,6 +82,24 @@ class GameScene extends Phaser.Scene {
} }
update(time, delta) { update(time, delta) {
this.mapView.update(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 its 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;
}
} }
} }