Canvas
ClassA root of the 2D ScreenTransform hierarchy in 3D space.
- Available on all platforms
A root of the 2D ScreenTransform hierarchy in 3D space. Also used to configure unit settings of Orthographic Camera.
Index
Properties
Methods
Remarks
SceneObjects with ScreenTransform can be placed on the Canvas, and the Canvas can be sized and placed anywhere in 3D space. It is like a painter’s canvas for ScreenTransforms.
Example
var canvas = script.getSceneObject().getComponent(Canvas.getTypeName());
print(canvas.pivot); // Outputs: {x: 0, y: 0}
// Note: this variable will be a COPY of canvas.pivot, not reference
var pivotCopy = canvas.pivot;
// Can mutate the copy then set it again
pivotCopy.x = 1;
pivotCopy.y = 1;
canvas.pivot = pivotCopy;
Extends
Properties
basisResolution
basisResolution:
vec2
The virtual resolution used when Canvas.offsetUnit is set to Pixels. Child ScreenTransform offset values are scaled by (Canvas size / basisResolution). For example, a basisResolution of (1080, 1440) on a 30x40 cm Canvas means an offset of 100 equals approximately 2.78 cm horizontally (100 / 1080 * 30). Setting this property will auto-adjust all descendant ScreenTransform offsets to preserve their visual positions. Has no effect when Canvas.offsetUnit is World.
Default Value
(1080, 1920)
debugRenderLayoutRect
debugRenderLayoutRect:
boolean
If enabled, draws the Canvas#layoutRect bounds as a wireframe for debugging Canvas layout.
Since
Lens Scripting Version 364
Default Value
false
enabled
enabled:
boolean
If disabled, the Component will stop enacting its behavior.
Default Value
true
Inherited from
isBeingDestroyed
readonlyisBeingDestroyed:boolean
Returns true if this Component is currently being destroyed. Becomes true as soon as
destruction begins via Component#destroy or destruction of its owning SceneObject,
before any OnDestroyEvent callbacks fire.
Since
Lens Scripting Version 364
Example
if (!script.isBeingDestroyed) {
// Component is still fully alive
}
Inherited from
isEnabledInHierarchy
readonlyisEnabledInHierarchy:boolean
Returns true if this Component, its SceneObject, and all of that SceneObjects parents are enabled.
Inherited from
Component.isEnabledInHierarchy
layoutRect
layoutRect:
Rect
The rectangular bounds that define the area child objects are laid out within. Each bound is defined as an offset in world units from the SceneObject's position.
Since
Lens Scripting Version 364
offsetScale
readonlyoffsetScale:vec2
The scale applied to child ScreenTransform offsets when Canvas.offsetUnit is Pixels (Canvas size / Canvas.basisResolution); returns (1, 1) for World offset units or when resolution is invalid.
offsetUnit
offsetUnit:
OffsetUnit
Controls whether child ScreenTransform offsets are in world units or virtual pixels. When set to Pixels, offsets are scaled by the Canvas size divided by Canvas.basisResolution. When set to World (default), offsets are in world units regardless of the basisResolution value. Setting this property will auto-adjust all descendant ScreenTransform offsets to preserve their visual positions.
Default Value
Canvas.OffsetUnit.World
pivot
pivot:
vec2
The point about which the Canvas Rectangle will rotate. Defined as fractional coordinates of the Canvas's dimensions. e.g. (1 , 1) brings the pivot to the top right corner of the canvas. Or (0.5, 0) moves the pivot to the right by half the canvas width.
Since
Lens Scripting Version 182
Default Value
(0, 0)
sceneObject
readonlysceneObject:SceneObject
The SceneObject this component is on.
Inherited from
sortingType
sortingType:
SortingType
The rendering sort order for the objects underneath this canvas.
Since
Lens Scripting Version 234
Default Value
Canvas.SortingType.Hierarchy
uniqueIdentifier
readonlyuniqueIdentifier:string
Since
Lens Scripting Version 176
Inherited from
unitType
unitType:
UnitType
The unit for the objects underneath this canvas.
Since
Lens Scripting Version 234
Default Value
Canvas.UnitType.World
Methods
destroy()
destroy():
void
Destroys the component.
Returns
void
Inherited from
getSceneObject()
getSceneObject():
SceneObject
Returns the SceneObject the component is attached to.
Returns
Inherited from
getSize()
getSize():
vec2
Get size of rectangle as (width, height)
Returns
getTransform()
getTransform():
Transform
Returns the Transform this component is attached to.
Returns
Inherited from
getTypeName()
staticgetTypeName():TypeName<Canvas>
Returns the fully-qualified JavaScript type name for this class (for example, "Component.Camera"). This is a static accessor (no instance required) and returns the same value as the instance getTypeName().
Returns
TypeName<Canvas>
Overrides
getTypeName()
getTypeName():
string
Returns the name of this object's type.
Returns
string
Inherited from
isOfType()
isOfType(
type):boolean
Returns true if the object matches or derives from the passed in type.
Parameters
| Parameter | Type |
|---|---|
type | string |
Returns
boolean
Inherited from
isSame()
isSame(
other):boolean
Returns true if this object is the same as other. Useful for checking if two references point to the same thing.
Parameters
| Parameter | Type |
|---|---|
other | ScriptObject |
Returns
boolean
Inherited from
setSize()
setSize(
value):void
Set size of rectangle as (width, height)
Parameters
| Parameter | Type |
|---|---|
value | vec2 |
Returns
void
See also
Canvas guide. Screen Transform Overview guide.
Nested types
Enumerations
| Enumeration | Description |
|---|---|
| OffsetUnit | The unit system for child ScreenTransform offsets on a Canvas. |
| SortingType | Used by Canvas to set how an object is sorted during rendering. |
| UnitType | Used by Canvas to set how an object is positioned. |