Skip to main content

Class: Viewport

camera/viewport.Viewport

Represents a Camera's viewable area and can be used to perform culling.

Constructors

constructor

โ€ข new Viewport(centre, width, height)

Creates a Viewport instance.

Parameters

NameTypeDescription
centrevec2The centre of the viewport in world space
widthnumberThe width of the viewport in world space
heightnumberThe height of the viewport in world space

Defined in

src/camera/viewport.ts:23

Properties

centre

โ€ข Private centre: vec2

Defined in

src/camera/viewport.ts:14


height

โ€ข Private height: number

Defined in

src/camera/viewport.ts:13


originalHeight

โ€ข Private originalHeight: number

Defined in

src/camera/viewport.ts:10


originalWidth

โ€ข Private originalWidth: number

Defined in

src/camera/viewport.ts:9


width

โ€ข Private width: number

Defined in

src/camera/viewport.ts:12

Methods

containsRectCollider

โ–ธ containsRectCollider(rect, worldToPixelScale): boolean

Checks wether the provided rectangle collider is contained within the viewport.

TODO: Change this to use physics collision system so it works with more than just RectCollider

Parameters

NameTypeDescription
rectRectColliderThe rect to check
worldToPixelScalevec2-

Returns

boolean

Wether or not the box is withing the viewport

Defined in

src/camera/viewport.ts:50


getHeight

โ–ธ getHeight(): number

Gets the viewport's height.

Returns

number

The viewport's height

Defined in

src/camera/viewport.ts:106


getOriginalHeight

โ–ธ getOriginalHeight(): number

Gets the height the viewport was given when constructed.

Returns

number

The viewport's original height

Defined in

src/camera/viewport.ts:124


getOriginalWidth

โ–ธ getOriginalWidth(): number

Gets the width the viewport was given when constructed.

Returns

number

The viewport's original width

Defined in

src/camera/viewport.ts:115


getWidth

โ–ธ getWidth(): number

Gets the viewport's width.

Returns

number

The viewport's width

Defined in

src/camera/viewport.ts:84


setHeight

โ–ธ setHeight(height): void

Sets the viewport's height.

throws When height is <= 0

Parameters

NameTypeDescription
heightnumberThe viewport's new height

Returns

void

Defined in

src/camera/viewport.ts:95


setWidth

โ–ธ setWidth(width): void

Sets the viewport's width.

throws When width is <= 0

Parameters

NameTypeDescription
widthnumberThe viewport's new width

Returns

void

Defined in

src/camera/viewport.ts:73


update

โ–ธ update(centre): void

Calculates the viewports bounds around a given centre.

Parameters

NameTypeDescription
centrevec2The centre of the viewport

Returns

void

Defined in

src/camera/viewport.ts:38