Update server/static/main.js
This commit is contained in:
@@ -80,13 +80,19 @@ class GameScene extends Phaser.Scene {
|
|||||||
// HUD zoom hook
|
// HUD zoom hook
|
||||||
window.setGameZoom = z => this.mapView.setZoom(z);
|
window.setGameZoom = z => this.mapView.setZoom(z);
|
||||||
}
|
}
|
||||||
update(time, delta) {
|
update(time, delta) {
|
||||||
this.mapView.update(delta);
|
// Move local player
|
||||||
// --- NEW: sync our actual current position to the server ---
|
if (this.mapView) {
|
||||||
|
this.mapView.update(delta);
|
||||||
|
}
|
||||||
|
|
||||||
|
// --- sync true current position to server ---
|
||||||
if (!this._lastPosSyncTime) this._lastPosSyncTime = 0;
|
if (!this._lastPosSyncTime) this._lastPosSyncTime = 0;
|
||||||
if (!this._lastPos) this._lastPos = { x: 0, y: 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(
|
const dist = Phaser.Math.Distance.Between(
|
||||||
pos.x,
|
pos.x,
|
||||||
pos.y,
|
pos.y,
|
||||||
@@ -94,7 +100,7 @@ class GameScene extends Phaser.Scene {
|
|||||||
this._lastPos.y
|
this._lastPos.y
|
||||||
);
|
);
|
||||||
|
|
||||||
// Only spam server if we moved enough or it’s been a bit
|
// Only send if we moved enough or some time has passed
|
||||||
if (dist > 8 || time - this._lastPosSyncTime > 250) {
|
if (dist > 8 || time - this._lastPosSyncTime > 250) {
|
||||||
socket.emit('pos:update', { x: pos.x, y: pos.y });
|
socket.emit('pos:update', { x: pos.x, y: pos.y });
|
||||||
this._lastPos = { x: pos.x, y: pos.y };
|
this._lastPos = { x: pos.x, y: pos.y };
|
||||||
|
|||||||
Reference in New Issue
Block a user