Update server/static/main.js
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user