Hexagon
Introduction¶
Hexagon grid object of Board system.
- Author: Rex
- Grid object of board
Usage¶
Create instance¶
var grid = scene.rexBoard.add.hexagonGrid({
x: 0,
y: 0,
cellWidth: 0,
cellHeight: 0,
// size: undefined,
staggeraxis: 1,
staggerindex: 1
});
or
// import { HexagonGrid } from 'phaser3-rex-plugins/plugins/board-components.js';
var grid = new HexagonGrid(config);
x
,y
: World position of origin tile (i.e. tileX = 0, tileY = 0)cellWidth
: The width of the cell, in pixels.cellHeight
: The height of the cell, in pixels.size
: Distance between center to each corner. GetcellWidth
andcellHeight
fromsize
if this parameter is notundefined
.staggeraxis
0
, ory
1
, orx
staggerindex
0
, oreven
1
, orodd
World position of tile (0, 0)¶
- Get
var worldX = grid.x; var worldY = grid.y;
- Set
or
grid.setOriginPosition(worldX, worldY);
grid.x = worldX; grid.y = worldY;
Cell size¶
- Get
var width = grid.width; var height = grid.height;
- Set
or
grid.setCellSize(width, height);
orgrid.width = width; grid.height = height;
grid.setCellRadius(size);
size
: Distance between center to each corner.
Grid type¶
- Get
var staggeraxis = grid.staggeraxis; var staggerindex = grid.staggerindex;
- Set
grid.setType(staggeraxis, staggerindex);
staggeraxis
0
, ory
1
, orx
staggerindex
0
, oreven
1
, orodd
Get world position¶
var worldXY = grid.getWorldXY(tileX, tileY); // worldXY: {x, y}
// var out = grid.getWorldXY(tileX, tileY, out);
Get tile position¶
var tileXY = grid.getTileXY(worldX, worldY); // tileXY: {x, y}
// var out = grid.getTileXY(worldX, worldY, out);
Directions¶
- staggeraxis =
0
/y
0
: Down-right1
: Down2
: Down-left3
: Up-left4
: Up5
: Up-right
- staggeraxis =
1
/x
0
: Right1
: Down-right2
: Down-left3
: Left4
: Up-left5
: Up-right