arcade2d
Class

AssetBundle

assets/asset-bundle.ts:43

A static, declarative description of a group of assets — a namespace plus a map of friendly key to load path — defined once at module scope and reused wherever those assets are loaded or fetched.

An AssetBundle is just data; it holds no reference to a Game or AssetLibrary and performs no loading itself. Bind it to a game's library with AssetLibrary.use to get a BoundAssetBundle whose load and get are wired to that library.

The point of declaring assets this way is compile-time key safety. Because the bundle captures its keys as literal types (via defineAssetBundle), BoundAssetBundle.get only accepts keys the bundle actually declares — a typo'd or never-declared key is a tsc error rather than a runtime ErrorCode.ASSET_NOT_FOUND that only fires when the object using it happens to spawn. This is the intended cure for "a rarely-encountered enemy's graphics component throws deep into a play session because its asset key was wrong."

Construct via defineAssetBundle, not new — the factory captures the entry keys as literal types, which the constructor's generic alone cannot.

Example

export const level1 = defineAssetBundle('level-1', {
  zombie: 'sprites/zombie.png',
  wall: 'tiles/wall.png',
});

const lvl = game.assets.use(level1);
await lvl.load();
const zombie = lvl.get('zombie'); // 'zombie' | 'wall' — checked by tsc

Constructors

#
constructor(namespace: string, entries: E): AssetBundle<E>

Parameters

  • namespace string
  • entries E

Properties

readonly #
entries: E

The key-to-path map. Keys are the compile-time-checked argument to BoundAssetBundle.get; values are loader paths.

readonly #
namespace: string

The namespace every entry is loaded into and looked up from. Also the unit BoundAssetBundle.unload frees.

ESC