Update server/static/map.js
This commit is contained in:
@@ -167,11 +167,14 @@ export class MapView {
|
||||
const seen = new Set();
|
||||
for (const p of players) {
|
||||
seen.add(p.id);
|
||||
const snapped = this.snapToTile(p.x, p.y);
|
||||
|
||||
// If you're using tiles:
|
||||
const pos = this.snapToTile ? this.snapToTile(p.x, p.y) : { x: p.x, y: p.y };
|
||||
|
||||
if (!this.otherSprites.has(p.id)) {
|
||||
const img = this.scene.add.image(snapped.x, snapped.y, 'other').setDepth(5);
|
||||
const img = this.scene.add.image(pos.x, pos.y, 'other').setDepth(5);
|
||||
const label = this.scene
|
||||
.add.text(snapped.x, snapped.y - 22, p.name || 'Player', {
|
||||
.add.text(pos.x, pos.y - 22, p.name || 'Player', {
|
||||
fontSize: '12px',
|
||||
color: '#9ca3af'
|
||||
})
|
||||
@@ -179,11 +182,12 @@ export class MapView {
|
||||
this.otherSprites.set(p.id, { img, label });
|
||||
} else {
|
||||
const rec = this.otherSprites.get(p.id);
|
||||
rec.img.setPosition(snapped.x, snapped.y);
|
||||
rec.label.setPosition(snapped.x, snapped.y - 22);
|
||||
rec.img.setPosition(pos.x, pos.y);
|
||||
rec.label.setPosition(pos.x, pos.y - 22);
|
||||
}
|
||||
}
|
||||
// Remove any that disappeared
|
||||
|
||||
// Clean up players that disconnected
|
||||
for (const [id, rec] of this.otherSprites) {
|
||||
if (!seen.has(id)) {
|
||||
rec.img.destroy();
|
||||
|
||||
Reference in New Issue
Block a user