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

    Class AppElement

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

    The element is sized like a replaced element such as <video>: a block-level box that the page's CSS controls, 300x150 by default. The application's canvas always fills the element, and the drawing buffer resolution follows the element's size (capped by max-pixel-ratio), tracked live via a ResizeObserver — so the element can be embedded at any size, resized by its container, or made fullscreen with ordinary CSS such as width: 100vw; height: 100dvh.

    Pointer input over the canvas is hit-tested against the scene and dispatched as pointer events on the entity elements under the pointer, where they behave like the DOM's own pointer events; picking controls when that happens. The canvas keeps receiving its native events too, so a listener on this element sees both kinds - event.target tells them apart.

    progress - Fired while the application preloads its assets. loaded and total are asset counts, not bytes, and an asset that fails to load still counts as loaded. Fired at least once per boot, and the final event always has loaded equal to total. Does not bubble.

    error - Fired when the application cannot boot because no graphics device could be created (for example, a browser with WebGL disabled). message names the requested backends and error holds the underlying failure. The element never becomes ready and app stays null — listen for this event to show a fallback UI. Removing the element and re-inserting it retries the boot with its current attributes. Does not bubble.

    Hierarchy (View Summary)

    Index
    • get alpha(): boolean

      Gets whether the frame buffer has an alpha channel.

      Returns boolean

      The alpha flag.

    • set alpha(value: boolean): void

      Sets whether the frame buffer has an alpha channel, which is what lets the page show through wherever the scene has not drawn. Read only when the application boots.

      Parameters

      • value: boolean

        The alpha flag.

      Returns void

    • get antialias(): boolean

      Gets whether the frame buffer is anti-aliased.

      Returns boolean

      The antialias flag.

    • set antialias(value: boolean): void

      Sets whether the frame buffer is anti-aliased. Read only when the application boots.

      Parameters

      • value: boolean

        The antialias flag.

      Returns void

    • get app(): AppBase | null

      The PlayCanvas application instance. null until the element is ready, and again once it has been removed from the document — await whenReady or the element's ready() promise before accessing it.

      Returns AppBase | null

      The application instance, or null.

    • get areaLightLuts(): string

      Gets the id of the <pc-asset> holding the area light lookup tables, whose loading also enables area lights for the application.

      Returns string

      The asset ID.

    • set areaLightLuts(value: string): void

      Sets the id of the <pc-asset> holding the area light lookup tables, whose loading also enables area lights for the application, so <pc-light> elements with a rect, disk or sphere shape render as intended. The asset is a JSON file with LTC_MAT_1 and LTC_MAT_2 arrays, like the PlayCanvas Engine examples' area-light-luts.json. The tables apply to the whole application and, when set before the application boots, load along with the other assets. Unlike the frame buffer options this applies immediately: clearing it switches area lights off again, though tables already handed to the engine stay in place. Devices that cannot render area lights ignore the switch, and omni and spot area lights stay punctual there.

      Parameters

      • value: string

        The asset ID.

      Returns void

    • get backend(): "webgpu" | "webgl2" | "null"

      Gets the graphics backend.

      Returns "webgpu" | "webgl2" | "null"

      The graphics backend.

    • set backend(value: "webgpu" | "webgl2" | "null"): void

      Sets the graphics backend. Defaults to 'webgpu', which falls back to 'webgl2' if WebGPU is not supported by the browser. Read only when the application boots.

      Parameters

      • value: "webgpu" | "webgl2" | "null"

        The graphics backend ('webgpu', 'webgl2', or 'null').

      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 depthBuffer(): boolean

      Gets whether the frame buffer has a depth buffer.

      Returns boolean

      The depth buffer flag.

    • set depthBuffer(value: boolean): void

      Sets whether the frame buffer has a depth buffer, which the renderer needs to resolve which surface is nearest the camera. Read only when the application boots.

      Parameters

      • value: boolean

        The depth buffer flag.

      Returns void

    • get devtools(): boolean

      Gets whether the application announces itself to developer tools, such as the PlayCanvas Inspector browser extension, so they can find and inspect it.

      Returns boolean

      Whether the application announces itself to developer tools.

    • set devtools(value: boolean): void

      Sets whether the application announces itself to developer tools, such as the PlayCanvas Inspector browser extension, so they can find and inspect it. Set false to keep a production page from announcing itself. This is an opt-out, not a protection: code running on the page can still reach the application, through this element's app property for one. Read only when the application boots. Defaults to true.

      Parameters

      • value: boolean

        Whether the application announces itself to developer tools.

      Returns void

    • get loadingBar(): boolean

      Gets whether the application shows its built-in loading bar while it boots and preloads its assets.

      Returns boolean

      The loading bar flag.

    • set loadingBar(value: boolean): void

      Sets whether the application shows its built-in loading bar while it boots and preloads its assets. Enabled by default; setting false removes the bar immediately, while setting true has no effect until the element is next connected. The bar can be themed with the CSS custom properties --pc-loading-bar-color, --pc-loading-bar-background and --pc-loading-bar-height.

      Parameters

      • value: boolean

        The loading bar flag.

      Returns void

    • get loadProgress(): number

      The asset preload progress of the application, as a fraction from 0 to 1. It is 0 until preloading begins (and again once the element has been removed from the document), and 1 once preloading has finished — including when there was nothing to preload. Read this to initialize a loading UI; subsequent updates arrive via the progress event.

      Returns number

      The preload progress.

    • get maxPixelRatio(): number

      Gets the cap on the pixel ratio the application renders at.

      Returns number

      The maximum pixel ratio.

    • set maxPixelRatio(value: number): void

      Sets the cap on the pixel ratio the application renders at. The canvas is sized by the smaller of this value and the display's own device pixel ratio, so the default of Infinity renders at full physical resolution, 1 renders at CSS resolution, and an intermediate value such as 2 keeps a dense display sharp without paying for every one of its pixels. Must be greater than 0. Unlike the other graphics options, this applies immediately.

      Parameters

      • value: number

        The maximum pixel ratio.

      Returns void

    • get physicsTimeScale(): number

      Gets the scale on the time the physics simulation advances by each frame, applied on top of time-scale: 0 pauses physics alone while the rest of the application keeps running.

      Returns number

      The physics time scale.

    • set physicsTimeScale(value: number): void

      Sets the scale on the time the physics simulation advances by each frame: below 1 is slow motion, above 1 speeds it up and 0 pauses it while the rest of the application keeps running. Applied on top of time-scale. Defaults to 1.

      Parameters

      • value: number

        The physics time scale.

      Returns void

    • get picking(): "auto" | "always" | "none"

      Gets how the application decides whether to pick the scene under the pointer, which it does to dispatch pointer events on entity elements: auto picks for an event type while a listener for it is registered on an entity element or <pc-scene>, always for every pointer event, and none never.

      Returns "auto" | "always" | "none"

      When to pick.

    • set picking(value: "auto" | "always" | "none"): void

      Sets when the application picks the scene under the pointer, which it does to dispatch pointer events on entity elements. Picking renders the scene again, so by default it only happens while something listens:

      • auto (the default) picks for an event type while a listener for it is registered on an entity element or on <pc-scene> - with addEventListener, an inline attribute such as onclick, or a handler property such as onpointerenter.
      • always picks for every pointer event. Listeners the element cannot see need it: one on the document or on another element outside the scene, or a framework's delegated handler, such as React's onPointerMove. React's onClick does not need it, because React also sets the onclick property of the element it is on.
      • none never picks, so no pointer events are dispatched on entities.

      Applies from the next pointer event.

      Parameters

      • value: "auto" | "always" | "none"

        When to pick ('auto', 'always' or 'none').

      Returns void

    • get stencilBuffer(): boolean

      Gets whether the frame buffer has a stencil buffer.

      Returns boolean

      The stencil buffer flag.

    • set stencilBuffer(value: boolean): void

      Sets whether the frame buffer has a stencil buffer, which stencil-based effects and UI masking need. Read only when the application boots.

      Parameters

      • value: boolean

        The stencil buffer flag.

      Returns void

    • get timeScale(): number

      Gets the scale on the time the application advances by each frame. Scripts, animation and physics all advance by the scaled time, so 0 pauses all three together.

      Returns number

      The time scale.

    • set timeScale(value: number): void

      Sets the scale on the time the application advances by each frame. Scripts, animation and physics all advance by the scaled time, so below 1 is slow motion, above 1 speeds it up and 0 pauses all three together. To pause or slow down physics alone, use physics-time-scale. Defaults to 1.

      Parameters

      • value: number

        The time scale.

      Returns void

    • get withCredentials(): boolean

      Gets whether asset requests send credentials (cookies and HTTP authentication) to other origins, which applies to every application on the page. Once the application has booted, this reports the engine's page-wide setting - which another <pc-app> may have switched on - rather than this element's own attribute.

      Returns boolean

      Whether asset requests send credentials.

    • set withCredentials(value: boolean): void

      Sets whether asset requests send credentials (cookies and HTTP authentication) to other origins, which the asset server must allow through CORS. The engine keeps this in its shared HTTP client, so it applies to every application on the page. Defaults to false.

      Parameters

      • value: boolean

        Whether asset requests send credentials.

      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 the <pc-entity>, <pc-model> or <pc-node> element whose backing entity is entity, or null if the entity is not fronted by an element of this application - for example, an unbound node inside a model's instantiated hierarchy, or an entity created through the engine API.

      Parameters

      • entity: Entity

        The entity to look up.

      Returns EntityBaseElement | null

      The element fronting the entity, or null.

    • 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<AppElement>

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