arcade2d
Class

Asset

assets/asset.ts:44

A 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

#
constructor(key: string, namespace: string, src: string): Asset

Parameters

  • key string
  • namespace string
  • src string

Properties

readonly #
key: string

The developer-facing name this asset is stored under within its Asset.namespace. Unique per namespace, not globally.

readonly #
namespace: string

The grouping this asset belongs to. The unit of bulk unloading via AssetLibrary.unloadNamespace.

readonly #
src: string

The resolved path the resource was loaded from. Also the underlying renderer's cache key, used to free the resource on unload.

abstract readonly #
type: AssetType

Discriminant identifying which concrete Asset subclass this is. Branch on it to safely narrow to the payload-bearing subclass. See the class-level docs for the narrowing pattern.

ESC