I’m working on a procedurally generated tilemap game and had a quick question around the typical workflow for using atlases with tilemaps.
Looking at the most excellent dungeon generator example I think I have the gist of it but I would like to take it one step further and instead of defining the mapping of tile names to tileset indexes manually I am using a json atlas file(texturepacker).
The thing that seems slightly unwieldy and makes me think I am missing something is I don’t see a way to pick a tile index based on the tile name within the atlas without creating that mapping manually. I am looking for something like map.putTileAt('TOP_WALL',0,0)
instead of map.putTileAt(0,0,0)
.
Below is my current solution:
let frames = atlasTexture.getFrameNames();
for (let i = 0; i < frames.length; i++) {
tileNameToIndex[frames[i]] = i;
}
map.putTileAt(tileNameToIndex['TOP_LEFT_WALL'],0,0)
map.putTileAt(tileNameToIndex['TOP_WALL'],1,0);
map.putTileAt(tileNameToIndex['TOP_RIGHT_WALL'],2,0);
map.putTileAt(tileNameToIndex['LEFT_WALL'],0,1);
map.putTileAt(tileNameToIndex['FLOOR1'],1,1);
map.putTileAt(tileNameToIndex['RIGHT_WALL'],2,1);
map.putTileAt(tileNameToIndex['BOTTOM_LEFT_WALL'],0,2);
map.putTileAt(tileNameToIndex['BOTTOM_WALL'],1,2);
map.putTileAt(tileNameToIndex['BOTTOM_RIGHT_WALL'],2,2);