Skip to main content

Canvas

Class

A root of the 2D ScreenTransform hierarchy in 3D space.

  • Available on all platforms
Platform details: Snapchat, SPECS, Camera Kit Web, Camera Kit Mobile fully supported.

Platform details

  • Snapchat — Fully supported.

  • SPECS — Fully supported.

  • Camera Kit Web — Fully supported.

  • Camera Kit Mobile — Fully supported.

A root of the 2D ScreenTransform hierarchy in 3D space. Also used to configure unit settings of Orthographic Camera.

Index

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

Component.enabled


isBeingDestroyed

readonly isBeingDestroyed: 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

Component.isBeingDestroyed


isEnabledInHierarchy

readonly isEnabledInHierarchy: 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

readonly offsetScale: 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

readonly sceneObject: SceneObject

The SceneObject this component is on.

Inherited from

Component.sceneObject


sortingType

sortingType: SortingType

The rendering sort order for the objects underneath this canvas.

Since

Lens Scripting Version 234

Default Value

Canvas.SortingType.Hierarchy

uniqueIdentifier

readonly uniqueIdentifier: string

Since

Lens Scripting Version 176

Inherited from

Component.uniqueIdentifier


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

Component.destroy


getSceneObject()

getSceneObject(): SceneObject

Returns the SceneObject the component is attached to.

Returns

SceneObject

Inherited from

Component.getSceneObject


getSize()

getSize(): vec2

Get size of rectangle as (width, height)

Returns

vec2


getTransform()

getTransform(): Transform

Returns the Transform this component is attached to.

Returns

Transform

Inherited from

Component.getTransform


getTypeName()

static getTypeName(): 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

Component.getTypeName


getTypeName()

getTypeName(): string

Returns the name of this object's type.

Returns

string

Inherited from

Component.getTypeName


isOfType()

isOfType(type): boolean

Returns true if the object matches or derives from the passed in type.

Parameters

ParameterType
typestring

Returns

boolean

Inherited from

Component.isOfType


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

ParameterType
otherScriptObject

Returns

boolean

Inherited from

Component.isSame


setSize()

setSize(value): void

Set size of rectangle as (width, height)

Parameters

ParameterType
valuevec2

Returns

void

See also

Canvas guide. Screen Transform Overview guide.

Nested types

Enumerations

EnumerationDescription
OffsetUnitThe unit system for child ScreenTransform offsets on a Canvas.
SortingTypeUsed by Canvas to set how an object is sorted during rendering.
UnitTypeUsed by Canvas to set how an object is positioned.