Asset
assets/asset.ts:44A loaded, ready-to-use game resource managed by an AssetLibrary.
Asset is the abstract base of the engine's resource handles. Concrete
subclasses (ImageAsset, and audio/other kinds in future) carry the
parsed, GPU- or runtime-ready payload and expose it through a typed
accessor — never as raw bytes. Game code rarely constructs an Asset
directly; instead it preloads paths through AssetLibrary.load and
retrieves the resulting handle by key via AssetLibrary.get.
Identity
Every asset is identified by three immutable fields:
- Asset.key — the developer-facing name the asset is stored under
within its namespace. Defaults to the load path but is usually a short
friendly alias (
'player','tileset'). - Asset.namespace — the grouping the asset belongs to. Namespaces keep keys unique only within a group and are the unit of bulk unloading (see AssetLibrary.unloadNamespace).
- Asset.src — the resolved path the resource was loaded from. This doubles as the underlying loader's cache key, so it is what AssetLibrary.unload hands back to the renderer to free GPU memory.
Type discrimination
Asset.type is a discriminant: narrow on it to recover the concrete subclass and its payload accessor.
const asset = game.assets.get('player');
if (asset.type === AssetType.Image) {
// asset is an ImageAsset here
const { width, height } = asset as ImageAsset;
}Constructors
Properties
key: string The developer-facing name this asset is stored under within its Asset.namespace. Unique per namespace, not globally.
namespace: string The grouping this asset belongs to. The unit of bulk unloading via AssetLibrary.unloadNamespace.
src: string The resolved path the resource was loaded from. Also the underlying renderer's cache key, used to free the resource on unload.