Skip to main content

Viewport

OBR.viewport​

Control the viewport of the current scene.

The viewport represents this players view of the current scene.

Reference

Methods​

reset​

async reset()

Reset the viewport to the initial view.

If no map exists in the scene this will be the origin. If a map exists the viewport will fit to this map.

Returns a ViewportTransform with the transform it was reset to.


animateTo​

async animateTo(transform)

Animate the viewport to the given transform.

Parameters

NAMETYPEDESCRIPTION
transformViewportTransformThe new transform to animate to

animateToBounds​

async animateTo(bounds)

Animate the viewport to the given bounding box.

Parameters

NAMETYPEDESCRIPTION
boundsBoundingBoxThe bounding box to animate to

Example

Zoom on to the selected items when clicking a context menu item

OBR.contextMenu.create({
id: "rodeo.owlbear.example",
icons: [
{
icon: "icon.svg",
label: "Example",
},
],
async onClick(context) {
OBR.viewport.animateToBounds(context.selectionBounds);
},
});

getPosition​

async getPosition()

Get the current position of the viewport.

Returns a Vector2.


setPosition​

async setPosition(position)

Set the position of the viewport.

Parameters

NAMETYPEDESCRIPTION
positionVector2The new position of the viewport

getScale​

async getScale()

Get the current scale of the viewport.

A scale of 1 represents a 1:1 scale.

Returns a number.


setScale​

async setScale(scale)

Set the scale of the viewport.

Parameters

NAMETYPEDESCRIPTION
scalenumberThe new scale of the viewport

getWidth​

async getWidth()

Get the width of the viewport.

Returns a number.


getHeight​

async getHeight()

Get the height of the viewport.

Returns a number.


transformPoint​

async transformPoint(point)

Transform a point from the viewport coordinate space into the screens coordinate space.

Parameters

NAMETYPEDESCRIPTION
pointVector2The point to transform

Returns a Vector2.


inverseTransformPoint​

async inverseTransformPoint(point)

Transform a point from the screens coordinate space into the viewport coordinate space.

Parameters

NAMETYPEDESCRIPTION
pointVector2The point to transform

Returns a Vector2.


Type Definitions​

ViewportTransform​

TYPE
object

Properties

NAMETYPEDESCRIPTION
positionVector2The position of the viewport
scalenumberThe scale of the viewport