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
});
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 not undefined.staggeraxis
0
, ory
1
, orx
staggerindex
0
, oreven
1
, orodd
Set world position of tile (0, 0)¶
grid.setOriginPosition(worldX, worldY);
Set cell size¶
grid.setCellSize(cellWidth, cellHeight);
Set grid type¶
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.getWorldXY(tileX, tileY); // tileXY: {x, y}
// var out = grid.getWorldXY(tileX, tileY, 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