HomeWeb Components API Reference - v0.10.1
    Preparing search index...

    Class AssetElement

    The AssetElement interface provides properties and methods for manipulating <pc-asset> elements. The AssetElement interface also inherits the properties and methods of the HTMLElement interface.

    The element becomes ready once the containing application has started and the asset is in the state declared by the markup: loaded for preloaded assets (even if loading failed — check the asset's resource), or registered and awaiting a load for lazy assets. Elements inserted while the application is running are created and registered on insertion, and begin loading immediately unless lazy. A pc-asset must be a direct child of pc-app — elements placed elsewhere, or with an unsupported asset type, never become ready.

    Apart from lazy, these attributes are read once when the asset is created, so changing them later has no effect.

    id - The identifier used to reference the asset from other elements.

    src - The URL of the asset to load.

    type - The asset type. Inferred from the src file extension when omitted.

    data - Additional asset data, as a JSON object.

    atlas - For a sprite asset, the id of the texture atlas asset it uses. The atlas must be declared before the sprite.

    frame-keys - For a sprite asset, the atlas frame keys it uses, separated by spaces or commas.

    pixels-per-unit - For a sprite asset, the number of pixels per world unit.

    render-mode - For a sprite asset, how the sprite is rendered when resized.

    load - Fired each time the asset finishes loading, including a lazy asset loaded later and any subsequent reloads. Does not bubble — listen on this element, or use a capture-phase listener on an ancestor to observe every asset.

    error - Fired when the asset fails to load, with the engine's error in message. Does not bubble. The element still becomes ready — readiness means the load settled, not that it succeeded.

    Hierarchy (View Summary)

    Index
    asset: Asset | null = null

    The asset that is loaded. Available once the element is ready — await whenReady or the element's ready() promise before accessing it.

    • get closestApp(): AppElement | null

      The nearest ancestor <pc-app> element, or null if this element has no <pc-app> ancestor. The search starts at the parent, so an element never resolves to itself.

      Returns AppElement | null

      The closest app element, or null.

    • get closestEntity(): EntityElement | null

      The nearest ancestor <pc-entity> element, or null if this element has no <pc-entity> ancestor. The search starts at the parent, so an element never resolves to itself.

      Returns EntityElement | null

      The closest entity element, or null.

    • get lazy(): boolean

      Gets whether the asset should be loaded lazily.

      Returns boolean

      The lazy loading flag.

    • set lazy(value: boolean): void

      Sets whether the asset should be loaded lazily.

      Parameters

      • value: boolean

        The lazy loading flag.

      Returns void

    • Called when the element is fully initialized and ready. Subclasses should call this when they're ready. Resolves the ready promise and dispatches a bubbling, composed ready event.

      Returns void