Skip to main content

Grid

OBR.scene.grid

Interact with the scene's grid.

Reference

Methods

getDpi

async getDpi()

Get the dots per inch (DPI) of the grid. Determines the resolution of one grid cell. For square grids this represents both the width and height of the grid cell. For vertically oriented hex grids this is the width of the grid cell. For horizontally oriented hex grids this is the height of the grid cell.

returns a number.


getScale

async getScale()

Get the current scale of the grid.

Returns a GridScale.


setScale

async setScale(scale)

Set the scale of the grid as a raw string.

Parameters

NAMETYPEDESCRIPTION
scalestringThe new raw scale of the grid

Example

OBR.scene.grid.setScale("5ft");

getColor

async getColor()

Get the current color of the grid.

Returns a GridColor.


setColor

async setColor(color)

Set the color of the grid.

Parameters

NAMETYPEDESCRIPTION
colorGridColorThe new color of the grid

Example

OBR.scene.grid.setColor("DARK");

getOpacity

async getOpacity()

Get the current opacity of the grid between 0 and 1.

Returns a number.


setOpacity

async setOpacity(opacity)

Set the opacity of the grid.

Parameters

NAMETYPEDESCRIPTION
opacitynumberThe new opacity of the grid between 0 and 1

getType

async getType()

Get the current grid type.

Returns a GridType.


setType

async setType(type)

Set the type of the grid.

Parameters

NAMETYPEDESCRIPTION
typeGridTypeThe new type of the grid

Example

OBR.scene.grid.setType("HEX_VERTICAL");

getLineType

async getLineType()

Get the current grid line type.

Returns a GridLineType.


setLineType

async setLineType(lineType)

Set the type of the grid line.

Parameters

NAMETYPEDESCRIPTION
lineTypeGridLineTypeThe new type of the grid line

Example

OBR.scene.grid.setLineType("DASHED");

getMeasurement

async getMeasurement()

Get the current grid measurement type.

Returns a GridMeasurement.


setMeasurement

async setMeasurement(measurement)

Set the measurement type of the grid.

Parameters

NAMETYPEDESCRIPTION
measurementGridMeasurementThe new measurement type of the grid

Example

OBR.scene.grid.setMeasurement("EUCLIDEAN");

snapPosition

async snapPosition(position, snappingSensitivity, useCorners)

Snap a Vector2 position to the nearest grid cell using the current grid settings.

Returns a Vector2 with the new position.

Parameters

NAMETYPEDESCRIPTION
positionVector2The position to snap
snappingSensitivitynumberAn optional number between 0 and 1. Leave undefined to use the users snapping preference. A value of 0 will disable snapping. A value of 1 will completely snap to the grid.
useCornersbooleanAn optional boolean. If true the corners of the grid cell will be valid snap locations. Defaults to true.
useCenterbooleanAn optional boolean. If true the center of the grid cell will be a valid snap location. Defaults to true.

getDistance

async getDistance(from, to)

Get the distance between two Vector2s on the Scenes grid.

Returns the shortest distance between the two inputs using the current GridMeasurement for the scene. When set to "EUCLIDEAN" this will be the exact distance. For all other measurement types this will be an integer of how many grid cells were traversed.

Parameters

NAMETYPEDESCRIPTION
fromVector2The start position in pixels
toVector2The end position in pixels

onChange

onChange(callback);

Parameters

NAMETYPEDESCRIPTION
callback(grid: Grid) => voidA callback for when the grid changes

Returns a function that when called will unsubscribe from change events.

Example

/**
* Use an `onChange` event with a React `useEffect`.
* `onChange` returns an unsubscribe event to make this easy.
*/
useEffect(
() =>
OBR.scene.grid.onChange((grid) => {
// React to grid changes
}),
[]
);

Type Definitions

Grid

The grid for a scene.

TYPE
object

Properties

NAMETYPEDESCRIPTION
dpinumberDots per inch of the scene. Determines the resolution of one grid cell. For square grids this represents both the width and height of the grid cell. For vertically oriented hex grids this is the width of the grid cell. For horizontally oriented hex grids this is the height of the grid cell.
styleGridStyleThe style of the grid
typeGridTypeThe type of the grid
measurementGridMeasurementThe measurement type of the grid
scalestringThe raw scale of the grid. For example 5ft

GridStyle

The style of a grid.

TYPE
object

Properties

NAMETYPEDESCRIPTION
lineTypeGridLineTypeThe style of the grid line
lineOpacitynumberThe opacity of the grid line between 0 and 1
lineColorGridColorThe color of the grid line

GridLineType

The type of a grid line.

TYPEvalues
string"SOLID" | "DASHED"

GridColor

The color of a grid line.

TYPEvalues
string"DARK" | "LIGHT" | "HIGHLIGHT"

GridType

The type of a grid.

TYPEvalues
string"SQUARE" | "HEX_VERTICAL" | "HEX_HORIZONTAL"

GridMeasurement

The type of a grid measurement.

TYPEvalues
string"CHEBYSHEV" | "ALTERNATING" | "EUCLIDEAN" | "MANHATTAN"

GridScale

The scale of a grid.

TYPE
object

Properties

NAMETYPEDESCRIPTION
rawstringThe raw grid scale. For example 5ft
parsedParsedGridScaleThe raw grid scale parsed into a more usable form

ParsedGridScale

The raw grid scale parsed into a more usable form

TYPE
object

Properties

NAMETYPEDESCRIPTION
multipliernumberThe number multiplier of the scale. For example 5 for a 5ft scale
unitstringThe unit of the scale. For example ft for a 5ft scale
digitsnumberThe precision of the scale. For example 2 for a 5.00ft scale