Skip to main content

Rect

Class

An axis aligned rectangle.

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

An axis aligned rectangle. Used by anchors and offsets in ScreenTransform to represent screen boundaries. Rect can only store finite numbers in the range Number.MIN_VALUE to Number.MAX_VALUE.

Index

Example

// @input Component.ScreenTransform screenTransform

// Move the ScreenTransform's anchor center
script.screenTransform.anchors.setCenter(new vec2(-0.25, 0.5));

// Change the ScreenTransform's anchor size
script.screenTransform.anchors.setSize(new vec2(0.25, 0.25));

Extends

Properties

bottom

bottom: number

The y position of the rectangle's bottom side.

Default Value

0

left

left: number

The x position of the rectangle's left side.

Default Value

0

right: number

The x position of the rectangle's right side.

Default Value

0

top

top: number

The y position of the rectangle's top side.

Default Value

0

Methods

create()

static create(left, right, bottom, top): Rect

Creates a new Rect with the given properties.

Parameters

ParameterType
leftnumber
rightnumber
bottomnumber
topnumber

Returns

Rect


getCenter()

getCenter(): vec2

Returns the rectangle's center position as (x, y).

Returns

vec2


getSize()

getSize(): vec2

Returns the size of the rectangle as (width, height).

Returns

vec2


getTypeName()

static getTypeName(): TypeName<Rect>

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<Rect>

Overrides

ScriptObject.getTypeName


getTypeName()

getTypeName(): string

Returns the name of this object's type.

Returns

string

Inherited from

ScriptObject.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

ScriptObject.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

ScriptObject.isSame


setCenter()

setCenter(value): void

Sets the rectangle's center position while maintaining its size.

Parameters

ParameterType
valuevec2

Returns

void


setSize()

setSize(value): void

Sets the rectangle's size while maintaining its center position.

Parameters

ParameterType
valuevec2

Returns

void


toString()

toString(): string

Returns a string representation of the Rect.

Returns

string