Hi, so, I'm kinda new to all of this but do have *sort* of a grasp on C++. I know that my issue is potentially a bit general, but unfortunately I am unsure on where else to ask.
I am currently working on my own tilemap system that uses a string that forms a room of arbitrary size (currently set to 16x12 tiles). If I edit the "position" and "texcoords" values manually I can successfully use the vertex array to display a tile in one place with a single sprite. More accurately, this is simply the entire vertex array set to a single tile and overlapping each other, but my point still stands.
When I modify this to use the "iterator", which should form the entire grid of tiles, no tiles are displayed at all. Could anyone help me with this? I'm at a loss on things to try.
Thanks.
void RoomController::LoadRoom()
{
//First parse the string from the specific room
//For now, use the given room
string room = rooms[0];
istringstream roomParser(room);
string tile;
//Create a blank vertex array
VertexArray tiles(Quads, 4 * roomXSize * roomYSize);
while(getline(roomParser, tile, ','))
{
//Create an iterator that acts as a base for all calculations following
int iterator = roomXSize * yIterator + xIterator;
//Get the current tile
int currentTile = stoi(tile);
//Get the position in the tilesheet
int tileXPos = tilesetCoordinates[currentTile].x;
int tileYPos = tilesetCoordinates[currentTile].y;
cout << "Tile:" << iterator << "\n";
cout << "The X position of the tile sprite is:" << tileXPos << "\n";
cout << "The Y position of the tile sprite is:" << tileYPos << "\n";
//Set their positions
int x1 = 8 * xIterator;
int y1 = 8 * yIterator;
int x2 = (8 * xIterator) + 8;
int y2 = (8 * yIterator) + 8;
tiles[0 + iterator].position = Vector2f(x1, y1);
tiles[1 + iterator].position = Vector2f(x2, y1);
tiles[2 + iterator].position = Vector2f(x2, y2);
tiles[3 + iterator].position = Vector2f(x1, y2);
//Set their texture
x1 = tileXPos;
y1 = tileYPos;
x2 = tileXPos + 8;
y2 = tileYPos + 8;
tiles[0 + iterator].texCoords = Vector2f(x1, y1);
tiles[1 + iterator].texCoords = Vector2f(x2, y1);
tiles[2 + iterator].texCoords = Vector2f(x2, y2);
tiles[3 + iterator].texCoords = Vector2f(x1, y2);
if (xIterator < 16)
{
xIterator += 1;
}
else
{
xIterator = 0;
yIterator += 1;
}
}
//sets it to the map
currentRoom = tiles;
}
Apologies for the quote, I am unsure of how to use code blocks on this forum.