Constructor
new BaseHexagonalGrid(options)
Construct a basic hexagonal grid
Parameters:
| Name | Type | Description | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
Object | Optional values to define the grid
Properties
|
Members
default_options
Defines what the default values are for the options of this class when
instantiated, see `BaseHexagonalGrid.Constructor` for more details.
Methods
animate()
Used to update and render the grid once per frame, locked to run
at most `BaseHexagonalGrid.fps` frames per second.
calculateGridWidth(hexagonalRadius, radiusopt)
Calculates the minimum width and height needed to fit `radius` nodes
with a hexagonal radius of `hexagonalRadius`
Parameters:
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
hexagonalRadius |
Number | The distance from the center of all nodes to the edge | ||
radius |
integer |
<optional> |
BaseHexagonalGrid.radius | The grid radius that should be visible |
calculateNodeRadius(widthopt, heightopt, radiusopt)
Calculates the maximum hexagonal radius for each node such that
all `radius` worth of nodes within `width` and `height`
Parameters:
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
width |
integer |
<optional> |
100 | The width of the space to fill |
height |
integer |
<optional> |
100 | The height of the space to fill |
radius |
integer |
<optional> |
BaseHexNode.radius | The grid radius that should be visible |
initialise()
Used to create and define nodes, called automatically one time when
class is instantiated. Calls `BaseHexagonalGrid.preInitialise()`,
then `BaseHexagonalGrid.initialiseNode(node, data) for each node`
and finally `BaseHexagonalGrid.postInitialise()`.
initialiseNode()
An overridable function that is called once for each node in
`BaseHexagonalGrid.nodes` during `BaseHexagonalGrid.initialise()`.
Default behaviour is to do nothing.
postInitialise()
An overridable function that is called at the end of
`BaseHexagonalGrid.initialise()`. Default behaviour is to do nothing.
postRender()
An overridable function that is called at the end of
`BaseHexagonalGrid.render()`. Default behaviour is to do nothing.
postUpdate()
An overridable function that is called at the end of
`BaseHexagonalGrid.update()`. Default behaviour is to do nothing.
preInitialise()
An overridable function that is called at the beginning of
`BaseHexagonalGrid.initialise()`. Default behaviour is to
populate `BaseHexagonalGrid.nodes` with with every node within
`BaseHexagonalGrid.radius` of `BaseHexagonalGrid.center`, and
to define `BaseHexagonalGrid.nodeData[node] = {}` for each
node.
preRender()
An overridable function that is called at the start of
`BaseHexagonalGrid.render()`. Default behaviour is to do nothing.
preUpdate()
An overridable function that is called at the start of
`BaseHexagonalGrid.update()`. Default behaviour is to do nothing.
render()
Used to update nodes, called automatically at the start of each
`BaseHexagonalGrid.animate` call. Calls
`BaseHexagonalGrid.preRender()`, then
`BaseHexagonalGrid.renderNode(node, data) for each node`
and finally `BaseHexagonalGrid.postRender()`.
renderNode()
An overridable function that is called once for each node in
`BaseHexagonalGrid.nodes` during `BaseHexagonalGrid.render()`.
Default behaviour is to do nothing.
setRadius(radius)
Set the grid radius and regenerate nodes
Parameters:
| Name | Type | Description |
|---|---|---|
radius |
integer | The desired radius |
update()
Used to update nodes, called automatically at the start of each
`BaseHexagonalGrid.animate` call. Calls
`BaseHexagonalGrid.preUpdate()`, then
`BaseHexagonalGrid.updateNode(node, data) for each node`
and finally `BaseHexagonalGrid.postUpdate()`.
updateNode()
An overridable function that is called once for each node in
`BaseHexagonalGrid.nodes` during `BaseHexagonalGrid.update()`.
Default behaviour is to do nothing.