Skip to main content

<Screen/>

The <Screen/> component turns an <Entity/> into a 2D UI screen that lays out <Element/> children. By default it renders in screen space (a 2D overlay), but it can also be placed in world space for in-scene UI. Use referenceResolution and scaleMode to control how the UI scales across different display sizes.

Usage

Attach a <Screen/> to an <Entity/>, then nest entities carrying an <Element/> to draw text or images.

<Entity name="screen">
<Screen referenceResolution={[1280, 720]} />
<Entity name="label">
<Element type="text" text="Hello, World!" />
</Entity>
</Entity>

This example renders a centred line of screen-space text using a <Screen/> and a text <Element/>.

Learn more about the Screen Component in the PlayCanvas documentation.

Properties

NameTypeDefault
screenSpace?
boolean
Whether the screen is rendered in screen space.
true
referenceResolution?
[number, number]
The reference resolution of the screen.
[1280, 720]
scaleMode?
"blend" | "stretch" | "fit"
The scale mode of the screen.
"blend"
cull?
boolean
If true, then elements inside this screen will not be rendered when outside of the screen (only valid when screenSpace is true).
-
resolution?
[number, number]
Sets the width and height of the ScreenComponent. When screenSpace is true, the resolution will always be equal to GraphicsDevice#width by GraphicsDevice#height . Gets the width and height of the ScreenComponent.
-
scaleBlend?
number
Sets the scale blend. This is a value between 0 and 1 that is used when scaleMode is equal to SCALEMODE_BLEND. Scales the ScreenComponent with width as a reference (when value is 0), the height as a reference (when value is 1) or anything in between. Defaults to 0.5. Gets the scale blend.
-
priority?
number
Sets the screen's render priority. Priority determines the order in which ScreenComponents in the same layer are rendered. Number must be an integer between 0 and 127. Priority is set into the top 8 bits of the ElementComponent#drawOrder property. Defaults to 0. Gets the screen's render priority.
-
system?
ComponentSystem
The ComponentSystem used to create this Component.
-
entity?
Entity
The Entity that this Component is attached to.
-
enabled?
boolean
Sets the enabled state of the component. Gets the enabled state of the component.
-