Class Viewport extends MessageDispatcher

Manages viewport, handles DOM container resize events and updates internal data.
When firing resize event stage bounds will be not up to date. Listen for stage's resize message instead.

Methods

Viewport(containerElement) constructor

constructor

Parameters
containerElement : HTMLElement | null — The native HTML element.
refresh() method
Refreshes viewport size and posts Message.RESIZE message. Make sure to refresh stage too in case container has changed its size.

Inherited Methods

on(name, callback, context) inherited method

Adds listener by given name and callback.

Parameters
name : string — Message name.
callback : function — Function to be called on message send.
context : * — Object to be used as this in callback function.
Returns
MessageBinding
off(names) inherited method

Removes all bindings by given message name.

Parameters
names : string — One or more message name.
Returns
void
once(name, callback, context) inherited method

Adds listener by given name and callback. Binding will be automatically removed after first execution.

Parameters
name : string — Message name.
callback : function — Function to be called on message send.
context : * — Object to be used as this in callback function.
Returns
MessageBinding
post(name, params) inherited method

Posts message with a given params.

Adding ~ character to the begging of the name will bubble message to the top of the tree.

Parameters
name : string — The name of a message
params : * — A list of params to send
Returns
void

Properties

orientation : Orientation property
Gets/Sets stage orientation.
orientationLock : boolean property
Gets/sets whenever stage orientation should be locked. If false and orientation is not universal stage will remain same size in both orientation.
size : Rectangle property
Returns the size of a viewport.
nativeElement : Element property
Returns the HTML container element the viewport runs in.
rotation : number property

Returns viewport orientation.

-1 is for -90 degrees
0 is for 0 degrees
1 is for 90 degrees
isLandscape : boolean property
Returns true if device is in landscape orientation.
isPortrait : boolean property
Returns true if device is in portrait orientation.

Inherited Properties

parent : MessageDispatcher | null inherited property
Returns parent MessageDispatcher.
stage : Stage | null inherited property
Returns the stage Game Object to which this belongs to or null if not added onto stage.
path : string | null inherited property
Returns string representing a url like path to this object in the display
tree.

Messages

resize message
Posted every time viewport size has changed.