Update server/static/main.js

This commit is contained in:
2025-11-13 17:37:51 +00:00
parent 1e2af2011d
commit ed6eb6d2a0

View File

@@ -81,12 +81,18 @@ class GameScene extends Phaser.Scene {
window.setGameZoom = z => this.mapView.setZoom(z);
}
update(time, delta) {
// Move local player
if (this.mapView) {
this.mapView.update(delta);
// --- NEW: sync our actual current position to the server ---
}
// --- 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 its 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 };