Update server/static/main.js

This commit is contained in:
2025-11-13 17:44:54 +00:00
parent ed6eb6d2a0
commit 4217212d62

View File

@@ -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;
}
}