`BT.loadingAssetsCount` is the combined count of in-flight image, audio and font loads. Poll it each frame and draw a spinner (or a "Loading..." label) until it returns to `0`. Font loads count from engine 1.9.0; on an older engine the count covers only images and audio, so upgrade `blit386` if a font must be part of the wait.
Installs into .claude/skills of the current project.
Sponsors
SSkills DirectorySkills Directory
Know which skills are safe — weekly.
SSkills DirectorySkills Directory
Is that skill safe to install?
Are you the author of Show A Loading Screen?
Add the live security badge to your README. It updates with every re-scan.
[](https://www.skillsdirectory.com/skills/blit386-show-a-loading-screen)
---
name: show-a-loading-screen
description:
Show a loading spinner or progress UI while sprites, audio and fonts finish loading, using BT.loadingAssetsCount and
optional SpriteSheet.status / progress. Use when the user wants a loading screen, progress bar, or asks how to wait
for assets before starting play. For the built-in BLIT386 splash (which already covers init() in release builds), see
docs/basics.md.
---
# Show a loading screen
`BT.loadingAssetsCount` is the combined count of in-flight image, audio and font loads. Poll it each frame and draw a
spinner (or a "Loading..." label) until it returns to `0`. Font loads count from engine 1.9.0; on an older engine the
count covers only images and audio, so upgrade `blit386` if a font must be part of the wait.
## The BLIT386 splash already covers init()
A real build shows the BLIT386 splash before your game starts by default, and its hold extends until `init()` settles.
When it plays there is already something on screen while you load, so awaiting your loads inside `init()` costs the
player nothing.
Do not assume it is there. A game can switch it off with `isSplashEnabled: false` in `configure()`, a player can add
`?nosplash` to the URL, and a development build skips it unless `?splash` is passed. So write your own loading UI when
you need it _after_ the splash has gone - a level load mid-game, or assets you deliberately start after `init()` returns
\- and whenever loads are slow enough to matter without it.
## How to do it
If you `await` every load inside `init()`, the game loop does not start until they finish - so there is nothing to draw
a spinner on. To show a loading screen, return from `init()` quickly and start the loads afterward (or in a helper you
do not await from `init()`). Then poll the counter every frame:
```js
import { AudioClip, BT, Color32, SpriteSheet, Vector2i } from 'blit386';
// The starter game already names its color slots 1 to 4 (COLOR_BACKGROUND up to COLOR_TEXT).
// The sprite's colors go in the slots after them, so loading it never overwrites those.
const FIRST_SPRITE_SLOT = COLOR_TEXT + 1;
async init() {
// 64 slots instead of the starter's 16, so the sprite's colors fit too.
this.palette = BT.paletteCreate(64);
// Set the loading screen's colors BEFORE the first frame: every slot after 0 starts out black,
// so 'Loading...' in an unset slot is black text on a black screen.
this.palette.set(COLOR_BACKGROUND, new Color32(18, 22, 40)); // dark blue
this.palette.set(COLOR_TEXT, new Color32(235, 240, 255)); // near white
BT.paletteSet(this.palette);
this.hero = null;
// Start loads WITHOUT awaiting them here, so update/render can run a loading UI.
void this.boot();
return true;
}
async boot() {
const hero = await SpriteSheet.loadIndexed('/sprites/hero.png', this.palette, FIRST_SPRITE_SLOT);
this.hero = hero.sheet;
this.heroRect = hero.srcRect;
this.theme = await AudioClip.load('/audio/theme.wav');
}
update() {
// Still loading (first boot or a hot-replaced asset under public/).
if (BT.loadingAssetsCount > 0 || !this.hero) {
return;
}
// ... normal update ...
}
render() {
BT.clear(COLOR_BACKGROUND);
if (BT.loadingAssetsCount > 0 || !this.hero) {
BT.systemPrint(new Vector2i(8, 8), COLOR_TEXT, 'Loading...');
return;
}
BT.drawSprite(this.hero, this.heroRect, new Vector2i(120, 90));
}
```
### Per-sheet status (hot-reload replacements)
After a PNG under `public/` is replaced, that sheet reports:
- `sheet.status` - `'loading' | 'ready' | 'failed'`
- `sheet.progress` - coarse `0` or `1.0` (not a percentage)
A normally loaded sheet is `'ready'` with `progress` `1.0`. Use these for a per-image indicator; use
`BT.loadingAssetsCount` for one engine-wide "anything still loading?" signal.
## Key calls
- `BT.loadingAssetsCount` (getter) - in-flight image + audio + font count; `0` means settled.
- `SpriteSheet.status` / `SpriteSheet.progress` (getters) - per-sheet hot-replace state.
## Notes
- Arrived in blit386 1.4.0. If the getter is missing, run `npx blit upgrade`.
- Small starters can still `await` everything in `init()` and skip a loading UI - that is fine. Use this skill when you
want the player to see progress (or when hot-reload replacements should show a brief "Loading..." state).
- Do not invent a fine-grained byte percentage from `progress`; it is intentionally coarse.
See `docs/basics.md` (including The splash) and `docs/hot-reload.md`.