Ive been learing sdl from this series. But the map.cpp from video does not work as intented, ive written diff map file but i still have 1 problem. Well, in the video the guy says that the tiles in the tileset should be accessed but row and col, but this does not work for me. I have 25 tiles in a 8×4 tileset but every tile has its uniqe number ( so for ex 19 ) and i cant access them using rows and cols (at least i dont know how to do that)
Here’s the code
void Map::LoadMap(std::string path, int sizeX, int sizeY) {
std::ifstream mapFile(path);
std::string line;
std::vector<std::vector<int>> mapData;
while (std::getline(mapFile, line)) {
std::istringstream ss(line);
std::vector<int> row;
std::string value;
while (std::getline(ss, value, ',')) {
row.push_back(std::stoi(value));
}
mapData.push_back(row);
}
for (int y = 0; y < sizeY; ++y) {
for (int x = 0; x < sizeX; ++x) {
int tileCode = mapData[y][x];
std::cout << tileCode << " ";
int srcX = tileCode % 10;
int srcY = tileCode / 10;
Game::AddTile(srcX * 32, srcY * 32, x * 32, y * 32);
}
}
mapFile.close();
}
If you hava any ideas please let me know.
I tried putting 0 before 1 digit number but i would still need to change the whole tileset and tbh it also didnt work bcs i need ints and converting 00 string to an int still gave me 0 (yeah now i know it wouldnt work even if a count came up with a 00 int)
Michał Trzcionka is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.