the bundle id
its asset descriptors (bundle ids cannot be nested)
loader.setBundle("common", [
{ name: "player", type: "image", src: "img/player.png" },
{ name: "font", type: "fontface", src: "font/PressStart2P.ttf" },
]);
loader.setBundle("level1", [
{ name: "level1", type: "tmx", src: "map/level1.tmx" },
{ name: "hills", type: "image", src: "img/hills.png" },
]);
loader.setBundle("level2", [
{ name: "level2", type: "tmx", src: "map/level2.tmx" },
{ name: "hills", type: "image", src: "img/hills.png" }, // shared
]);
// boot: behind the loading screen
await loader.preload(["common", "level1"]);
// moving on: load the next level, switch, then free the previous one
// ("hills" stays in memory: level2 lists it too)
await loader.load("level2");
await level.load("level2", { async: true });
loader.unload("level1");
Declare a bundle: a named list of the asset descriptors you would otherwise pass to loader.preload, to load and free together — typically the assets of one level, plus a
"common"bundle for what every level uses. Passing a record of bundles topreload({ common: [...], level1: [...] }, as an assets file exports it) declares each of its keys this way.A bundle is a lifetime, not a namespace: its assets keep their own names and live in the same caches as every other asset, so
getImage("tiles")andlevel.load("map1")read them as before. Bundle ids and asset names are separate, so a level's bundle may share its map's name. Load it with loader.load (or name it in a loader.preload list), check it with loader.isLoaded, and release it with loader.unload. An asset listed in several bundles is loaded once and freed with the last loaded bundle that lists it, so list a shared asset in every bundle that uses it.Declaring does not load anything, and a bundle can be declared before the parsers of custom types it uses are registered. Redefining an id replaces its list, but only while that bundle is not loaded or loading: unload it first. The list is copied, so changing the array afterwards changes nothing. An asset listed twice is one asset (type and name identify it), and an empty list is allowed: such a bundle loads at once and is always loaded.