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

    Class SpriteComponentElement

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

    A simple sprite (the default) renders one frame of the sprite asset it names. An animated sprite plays its <pc-sprite-clip> children instead, each a named clip with a sprite asset of its own: the clip attribute names the one that plays, and changing it switches playback. Sprites are unlit, and render as transparent geometry in the world layer.

    Engine component: SpriteComponent (sprite).

    Hierarchy (View Summary)

    Index
    • get asset(): string

      Gets the id of the pc-asset of the sprite to render (simple sprites only).

      Returns string

      The sprite asset id.

    • set asset(value: string): void

      Sets the id of the pc-asset of the sprite to render (simple sprites only). An empty value renders nothing.

      Parameters

      • value: string

        The sprite asset id.

      Returns void

    • get clip(): string

      Gets the name of the clip to play (animated sprites only).

      Returns string

      The clip name.

    • set clip(value: string): void

      Sets the name of the clip to play (animated sprites only). Changing it switches playback, and setting it again restarts a clip that has ended. The clip also plays whenever the sprite is enabled again. An empty value leaves the current clip playing.

      Parameters

      • value: string

        The clip name.

      Returns void

    • 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(): EntityBaseElement | null

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

      Returns EntityBaseElement | null

      The closest entity-fronting element, or null.

    • get enabled(): boolean

      Gets the enabled state of the component.

      Returns boolean

      The enabled state of the component.

    • set enabled(value: boolean): void

      Sets the enabled state of the component.

      Parameters

      • value: boolean

        The enabled state of the component.

      Returns void

    • get flipX(): boolean

      Gets whether the sprite is mirrored horizontally.

      Returns boolean

      Whether the sprite is flipped horizontally.

    • set flipX(value: boolean): void

      Sets whether the sprite is mirrored horizontally. Defaults to false.

      Parameters

      • value: boolean

        Whether to flip the sprite horizontally.

      Returns void

    • get flipY(): boolean

      Gets whether the sprite is mirrored vertically.

      Returns boolean

      Whether the sprite is flipped vertically.

    • set flipY(value: boolean): void

      Sets whether the sprite is mirrored vertically. Defaults to false.

      Parameters

      • value: boolean

        Whether to flip the sprite vertically.

      Returns void

    • get frame(): number

      Gets the index of the frame to render, as last set - on an animated sprite the playing clip moves on from it, so component.frame is the frame on screen.

      Returns number

      The frame index.

    • set frame(value: number): void

      Sets the index of the frame to render, among the frame keys of the current sprite. On an animated sprite it moves the playing clip to that frame, which plays on from there - but a clip starting to play begins at its first frame, so a frame declared in markup has no effect on an animated sprite. Defaults to 0.

      Parameters

      • value: number

        The frame index.

      Returns void

    • get height(): number

      Gets the height of the sprite in world units, used only when its sprite asset's render-mode is sliced or tiled.

      Returns number

      The height.

    • set height(value: number): void

      Sets the height of the sprite in world units, used only when its sprite asset's render-mode is sliced or tiled. Defaults to 1.

      Parameters

      • value: number

        The height.

      Returns void

    • get speed(): number

      Gets the playback speed multiplier applied to every clip.

      Returns number

      The playback speed multiplier.

    • set speed(value: number): void

      Sets the playback speed multiplier applied to every clip, where 0 freezes playback. Defaults to 1.

      Parameters

      • value: number

        The playback speed multiplier.

      Returns void

    • get type(): "simple" | "animated"

      Gets the type of the sprite: simple or animated.

      Returns "simple" | "animated"

      The sprite type.

    • set type(value: "simple" | "animated"): void

      Sets the type of the sprite. Can be:

      • simple - Renders one frame of the sprite asset.
      • animated - Plays the <pc-sprite-clip> children, starting with the one named by clip.

      Defaults to simple.

      Parameters

      • value: "simple" | "animated"

        The sprite type.

      Returns void

    • get width(): number

      Gets the width of the sprite in world units, used only when its sprite asset's render-mode is sliced or tiled.

      Returns number

      The width.

    • set width(value: number): void

      Sets the width of the sprite in world units, used only when its sprite asset's render-mode is sliced or tiled. Defaults to 1.

      Parameters

      • value: number

        The width.

      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. Signals at most once per readiness cycle: a repeat call before _resetReady has re-armed the promise does nothing.

      Returns void

    • Returns the ready promise to its pending state. Subclasses should call this when the resource their readiness announced is torn down (typically from disconnectedCallback), so that a later re-initialization can signal readiness again. Does nothing while the promise is still pending — an in-flight waiter carries over to the next readiness cycle rather than being stranded on a promise nothing will ever resolve.

      Returns void

    • Returns a promise that resolves with this element when it's ready. This is the low-level primitive underlying whenReady, which is the recommended way to wait for elements.

      Readiness tracks the element's current lifecycle: once a ready element is torn down (for example by removing it from the document), this returns a fresh promise that resolves when the element is next ready. A promise obtained earlier stays resolved — call this again after re-inserting an element rather than reusing a promise from before its removal.

      Returns Promise<SpriteComponentElement>

      A promise that resolves with this element when it's ready.