Fix missing trees at game start by generating them after npcWorldX is set
This commit is contained in:
@@ -1036,9 +1036,7 @@ class Game {
|
|||||||
this.show('map');
|
this.show('map');
|
||||||
this._showController(true);
|
this._showController(true);
|
||||||
|
|
||||||
/* We need the viewport size — defer a tick so the DOM is laid out */
|
|
||||||
requestAnimationFrame(() => {
|
requestAnimationFrame(() => {
|
||||||
this._generateTrees();
|
|
||||||
const world = document.getElementById('map-inner');
|
const world = document.getElementById('map-inner');
|
||||||
const viewW = world ? world.parentElement.offsetWidth : 420;
|
const viewW = world ? world.parentElement.offsetWidth : 420;
|
||||||
|
|
||||||
@@ -1048,14 +1046,14 @@ class Game {
|
|||||||
this.state.npcWorldX = Math.round(viewW * 3.5);
|
this.state.npcWorldX = Math.round(viewW * 3.5);
|
||||||
this.state.npcWorldY = 0;
|
this.state.npcWorldY = 0;
|
||||||
} else {
|
} else {
|
||||||
/* Always reset camera to 0 each question — keeps trees in view.
|
|
||||||
NPC spawns off-screen right relative to fresh origin. */
|
|
||||||
this.state.worldX = 0;
|
this.state.worldX = 0;
|
||||||
this.state.worldY = 0;
|
this.state.worldY = 0;
|
||||||
this.state.npcWorldX = Math.round(viewW * 3.0 + Math.random() * viewW * 0.8);
|
this.state.npcWorldX = Math.round(viewW * 3.0 + Math.random() * viewW * 0.8);
|
||||||
this.state.npcWorldY = 0;
|
this.state.npcWorldY = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this._generateTrees();
|
||||||
|
|
||||||
document.getElementById('hud-name').textContent = this.state.playerName||'ASH';
|
document.getElementById('hud-name').textContent = this.state.playerName||'ASH';
|
||||||
this.updateHUD();
|
this.updateHUD();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user