Error with loading images for tilemap tiles, please help.
I'm trying to load a tilemap for a tower defense game I'm working on. I am using loadTilemapfromCSV(), with this line of code:
_map.loadMapFromCSV("assets/tilemaps/play_tilemap.csv", "assets/tilemaps/GraveyardTDTileset3Image.png", Reg.TILE_SIZE, Reg.TILE_SIZE);
(Reg.TILE_SIZE is my tile size, currently 8.) The csv file loads fine, but when I try to load the tilemap I get errors. (I was previously using some code from the MinimalistTD example to generate my tileset.) The csv is mostly 1s, with some 0s representing the path, and some 2s representing special tiles.
The tile size is 8 by 8. This is built into the code, and when I try to change it the game crashes. So I tried using the 8 by 8 tileset below:
But this caused errors. It filled in the 1s with the second tile, the tombstone. It filled in the 2s with seemingly nothing, and the game crashed when I tried to spawn my first enemy (set to follow a path). When I removed the 2s the game ran without crashing. Also, the game ran just fine when I ran it with this (16 by 16) tileset:
But it only drew the top left quarter of the tombstone.
Can anyone please tell me how to get my tilemap working correctly? I have been trying for hours and I can't figure it out at all. Thanks.
The tiles in the tile set are graphic indexed starting with 0 (like an array). That's why it "fills the 1s with the second tile", essentially your graphic is missing tile 0 and it's all off by one. And it would crash when trying to draw tiles with index 2, because no such tile exists in the graphic.
You could just add a transparent 8x8 square as tile #0 (depending on what you want the "path" to look like).