Constructor
new HexagonalGrid()
Extends
Members
(static) flatHexPoints :Array.<Array.<number>>
A matrix of x and y offsets which is multiplied by the width/height vector to get flat-top polygon coordinates
Type:
(static) pointyHexPoints :Array.<Array.<number>>
A matrix of x and y offsets which is multiplied by the width/height vector to get pointy-top polygon coordinates
Type:
h
- Overrides:
Grid Unit Height
hexPoints
An array of the points which define a hexagon for this grid shape
highlight :Object
- Overrides:
Highlight active grid spaces
Type:
- Object
w
- Overrides:
Grid Unit Width
Methods
cubeToOffset(q, r, s) → {Object}
Convert a cube coordinate (q, r, s) into an offset coordinate (row, col). See https://www.redblobgames.com/grids/hexagons/ for reference Source code available https://www.redblobgames.com/grids/hexagons/codegen/output/lib-functions.js
Parameters:
Name | Type | Description |
---|---|---|
q |
number | Cube coordinate 1 |
r |
number | Cube coordinate 2 |
s |
number | Cube coordinate 3 |
Returns:
- Type
- Object
draw(previewopt) → {BaseGrid}
- Overrides:
Draw the grid. Subclasses are expected to override this method to perform their type-specific drawing logic.
Parameters:
Name | Type | Attributes | Description | |||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
preview |
object |
<optional> |
Override settings used in place of those saved to the scene data. Properties
|
Returns:
- Type
- BaseGrid
getCenter(x, y) → {Array.<number>}
- Overrides:
Given a pair of coordinates (x, y), return the center of the grid square which contains that point
Parameters:
Name | Type | Description |
---|---|---|
x |
number | The x-coordinate |
y |
number | The y-coordinate |
Returns:
An array [cx, cy] of the central point of the grid space which contains (x, y)
- Type
- Array.<number>
getGridPositionFromPixels(x, y) → {Array.<number>}
- Overrides:
Given a pair of pixel coordinates, return the grid position as an Array. Always round down to the nearest grid position so the pixels are within the grid space (from top-left).
Parameters:
Name | Type | Description |
---|---|---|
x |
number | The x-coordinate pixel position |
y |
number | The y-coordinate pixel position |
Returns:
An array representing the position in grid units
- Type
- Array.<number>
getNeighbors(row, col) → {Array.<number>}
- Overrides:
Get the grid row and column positions which are neighbors of a certain position
Parameters:
Name | Type | Description |
---|---|---|
row |
number | The grid row coordinate against which to test for neighbors |
col |
number | The grid column coordinate against which to test for neighbors |
Returns:
An array of grid positions which are neighbors of the row and column
- Type
- Array.<number>
getPixelsFromGridPosition(x, y) → {Array.<number>}
- Overrides:
Given a pair of grid coordinates, return the pixel position as an Array. Always round up to a whole pixel so the pixel is within the grid space (from top-left).
Parameters:
Name | Type | Description |
---|---|---|
x |
number | The x-coordinate grid position |
y |
number | The y-coordinate grid position |
Returns:
An array representing the position in pixels
- Type
- Array.<number>
getPolygon(x, y, wopt, hopt)
A convenience method for getting all the polygon points relative to a top-left [x,y] coordinate pair
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
x |
number | The top-left x-coordinate |
|
y |
number | The top-right y-coordinate |
|
w |
number |
<optional> |
An optional polygon width |
h |
number |
<optional> |
An optional polygon height |
getSnappedPosition(x, y, intervalopt) → {Object}
- Overrides:
Given a pair of coordinates (x1,y1), return the grid coordinates (x2,y2) which represent the snapped position Under a "gridless" system, every pixel position is a valid snapping position
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
x |
number | The exact target location x |
||
y |
number | The exact target location y |
||
interval |
number | null |
<optional> |
null
|
An interval of grid spaces at which to snap. At interval=1, snapping occurs at pixel intervals defined by the grid size At interval=2, snapping would occur at the center-points of each grid size At interval=null, no snapping occurs |
Returns:
An object containing the coordinates of the snapped location
- Type
- Object
getTopLeft() → {Array.<number>}
- Overrides:
Given a pair of coordinates (x, y) - return the top-left of the grid square which contains that point
Returns:
An Array [x, y] of the top-left coordinate of the square which contains (x, y)
- Type
- Array.<number>
highlightGridPosition(layer, x, y, color, border, alpha, shape)
- Overrides:
Highlight a grid position for a certain coordinates
Parameters:
Name | Type | Description |
---|---|---|
layer |
GridHighlight | The highlight layer to use |
x |
number | The x-coordinate of the highlighted position |
y |
number | The y-coordinate of the highlighted position |
color |
number | The hex fill color of the highlight |
border |
number | The hex border color of the highlight |
alpha |
number | The opacity of the highlight |
shape |
PIXI.Polygon | A predefined shape to highlight |
measureDistances(segments, options) → {Array.<number>}
- Overrides:
Measure the distance traversed over an array of measured segments
Parameters:
Name | Type | Description |
---|---|---|
segments |
Array.<object> | An Array of measured movement segments |
options |
MeasureDistancesOptions | Additional options which modify the measurement |
Returns:
An Array of distance measurements for each segment
- Type
- Array.<number>
offsetToCube(row, col) → {Object}
Convert an offset coordinate (row, col) into a cube coordinate (q, r, s). See https://www.redblobgames.com/grids/hexagons/ for reference Source code available https://www.redblobgames.com/grids/hexagons/codegen/output/lib-functions.js
Parameters:
Name | Type | Description |
---|---|---|
row |
number | The row number |
col |
number | The column number |
Returns:
- Type
- Object
shiftPosition(x, y, dx, dy)
- Overrides:
Shift a pixel position [x,y] by some number of grid units dx and dy
Parameters:
Name | Type | Description |
---|---|---|
x |
number | The starting x-coordinate in pixels |
y |
number | The starting y-coordinate in pixels |
dx |
number | The number of grid positions to shift horizontally |
dy |
number | The number of grid positions to shift vertically |