Improve game initialization by ensuring the stage is visible before Pixi.js initialization; synchronize renderer on menu to game switch for better rendering performance.
This commit is contained in:
@@ -139,6 +139,9 @@ async function ensureMap(): Promise<void> {
|
|||||||
async function openWorld(id: string): Promise<void> {
|
async function openWorld(id: string): Promise<void> {
|
||||||
try {
|
try {
|
||||||
setStatus('Loading map…', 'busy');
|
setStatus('Loading map…', 'busy');
|
||||||
|
// Stage must be visible before Pixi init / camera.fit — a hidden host measures as 0×0 and
|
||||||
|
// leaves the canvas stuck as a thin strip.
|
||||||
|
showGame();
|
||||||
await ensureMap();
|
await ensureMap();
|
||||||
const map = await api.getMap(id);
|
const map = await api.getMap(id);
|
||||||
|
|
||||||
@@ -148,10 +151,10 @@ async function openWorld(id: string): Promise<void> {
|
|||||||
view.showWorld(map);
|
view.showWorld(map);
|
||||||
elements.worldTitle.textContent = map.name;
|
elements.worldTitle.textContent = map.name;
|
||||||
elements.hud.textContent = '';
|
elements.hud.textContent = '';
|
||||||
showGame();
|
|
||||||
setStatus('');
|
setStatus('');
|
||||||
await refreshWorldList();
|
await refreshWorldList();
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
showMenu();
|
||||||
setStatus(`Could not open world: ${message(error)}`, 'error');
|
setStatus(`Could not open world: ${message(error)}`, 'error');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -98,6 +98,9 @@ export class MapView {
|
|||||||
this.labels.clear();
|
this.labels.clear();
|
||||||
this.worldSizeMeters = map.sizeMeters;
|
this.worldSizeMeters = map.sizeMeters;
|
||||||
|
|
||||||
|
// Host may have just become visible after a menu → game switch; sync the renderer before fitting.
|
||||||
|
this.app.resize();
|
||||||
|
|
||||||
this.paintBackground();
|
this.paintBackground();
|
||||||
this.camera.fit(map.sizeMeters, this.viewport);
|
this.camera.fit(map.sizeMeters, this.viewport);
|
||||||
this.chunks.setWorld(map.id, map.chunks);
|
this.chunks.setWorld(map.id, map.chunks);
|
||||||
|
|||||||
Reference in New Issue
Block a user