I have a C++ game project using SDL. Besides, I have a .js file for the tiled map (I attach a pastebin link for more detailed: https://pastebin.com/GKqs3km5). How can I use this to create map in my project? I try ifstream to read this file but it seems doesn't right.
//from lesson 39 Lazyfoo
for (int i = 0; i < TOTAL_TILES; ++i)
{
//Determines what kind of tile will be made
int tileType = -1;
//Read tile from file
js >> tileType;
//If the was a problem in reading the map
if (js.fail())
{
//Stop loading map
printf("Error loading map: Unexpected end of file!\n");
tilesLoaded = false;
break;
}
//If the number is a valid tile number
if ((tileType >= 0) && (tileType < TOTAL_TILE_SPRITES))
{
tiles[i] = new Tile(x, y, tileType);
}
Ditch the .js format. It was exported from Tiled, so open it in Tiled and re-export as JSON (or XML). Then use any JSON (or XML) parsing library.
There are probably specialized libraries for parsing the JSON/XML tiled maps, but since the format is so simple, you might as well use a generic library.