I’m trying to get a hexagonal tilemap working, and I haven’t got it to work so far. There are a lot of members in the mapData
object passed to this.make.tilemap
, and at first glance the only things that look neccesary for a hexagonal tilemap to work are data
, tileWidth
, tileHeight
, orientation
, staggerAxis
, staggerIndex
, and hexSideLength
. However, this code here:
map = this.make.tilemap({ data: [[1,2,0]], tileWidth: 200, tileHeight: 200, orientation: "hexagonal", staggeraxis: "y", staggerindex: "odd", hexSideLength: 80 });
tiles = map.addTilesetImage('tiles');
map.createLayer(0, tiles, 0, 0);
creates a orthogonal tilemap. So I tried using the “Tiled” software to make an example tilemap and see what I need for a hexagonal tilemap. Here’s what it came up with:
this.make.tilemap({
"compressionlevel":-1,
"height":20,
"hexsidelength":16,
"infinite":false,
"layers":[
{
"data":[1,2,0],
"height":20,
"id":1,
"name":"Tile Layer 1",
"opacity":1,
"type":"tilelayer",
"visible":true,
"width":30,
"x":0,
"y":0
}],
"nextlayerid":2,
"nextobjectid":1,
"orientation":"hexagonal",
"renderorder":"right-down",
"staggeraxis":"y",
"staggerindex":"odd",
"tiledversion":"1.10.1",
"tileheight":32,
"tilesets":[
{
"firstgid":1,
"source":"a.tsx"
}],
"tilewidth":32,
"type":"map",
"version":"1.10",
"width":30
});
At first I thought that this looks very bloated, and I wasn’t sure if most of this was even necessary. Like, infinite:false
? Do I seriously need this? But the thing that confused me most is layers[0].data
. Why is it not a 2-dimensional array? Can tilemaps also take 1-dimensional arrays as input? What’s going on?
So, what I want to know is,
- What is the bare minimum parameters that I need to pass to
make.tilemap
to get a hexagonal tilemap? Do I need all of them for it to work? - What’s up with the 1-dimensional array? Can I pass different types of array into
this.make.tilemap
and still get the same result?
Thank you!