mugon.net docs
SDKsJavaScript

Loading progress

How the loading overlay decides when to close, and how to feed it.

While your game loads, the platform shows an overlay with the launch steps and a progress bar. It closes when the first of these happens:

  • your game calls ctx.progress.done(), or
  • the callback you passed to Mugon.start finishes.

If neither ever happens the overlay stays, so a game whose callback runs for its whole lifetime (a game loop) must call ctx.progress.done() once it is playable.

The progress bar

The platform estimates progress from the bytes of your game's files it has served, out of the total size of the version's files, and never shows more than 99% until the game says it is done. That already gives a determinate bar for a game that just downloads a big file.

If your game knows better, report it:

ctx.progress.set(0.4, "Loading textures");

As soon as you report a fraction, it replaces the estimate. The label is shown under the bar. Fractions are clamped to 0..1.

Engines that report their own progress

Feed the engine's callback into ctx.progress.set and call done() when it finishes:

Mugon.start(async (ctx) => {
  await loadEngine({
    onProgress: (fraction) => ctx.progress.set(fraction),
  });
  ctx.progress.done();
});

Keeping the callback open

A wasm game started from the callback (Bevy) usually returns from its start function immediately while the app keeps running. Returning from the callback would close the overlay early, so keep it pending and let the game close the overlay itself:

Mugon.start(async () => {
  await init(); // starts the wasm
  await new Promise(() => {}); // the game calls loaded() when it is playable
});

In Bevy that is Bridge::loaded() or the MugonLoadingPlugin, see Bevy.

On this page