Welcome, Guest. Please login or register. Did you miss your activation email?

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - Noba

Pages: [1]
1
General / Re: Issues with tilemap system
« on: January 31, 2022, 11:45:17 am »
Hey guys, thanks for the responses. There were a few issues like this, but you're not going to believe what the main culprit was...

I had to change a 16 to a 15 where it resets xIterator and increments yIterator.  ::)

2
General / Re: Issues with tilemap system
« on: January 30, 2022, 02:29:48 pm »


The above string is normally set to a single line, I did this for visibility, and to show that the LUA is in fact fine.
Little bit of an update on this - It almost works! It didn't occur to me that the quads within the vertex array were actually smaller vertex arrays, so I changed up the position setting code and texture setting code to account for that. However, I now have this. Does anyone know what my problem could be? The map is definitely still 16x12, wondering if the problem is with my string generation code in LUA.

Edit: Definitely not. It's something to do with how I'm setting the quads.

Quote
      //Get a pointer to the current tile's quad
      Vertex* quad = &currentRoom[(xIterator + yIterator * roomXSize) * 4];

      //Set the positions of each of the 4 vertices
      int x1 = 8 * xIterator;
      int y1 = 8 * yIterator;
      int x2 = 8 * (1 + xIterator);
      int y2 = 8 * (1 + yIterator);
      quad[0].position = Vector2f(x1, y1);
      quad[1].position = Vector2f(x2, y1);
      quad[2].position = Vector2f(x2, y2);
      quad[3].position = Vector2f(x1, y2);

      //Set the texture coordinates of each of the 4 vertices
      x1 = tileXPos;
      y1 = tileYPos;
      x2 = tileXPos + 8;
      y2 = tileYPos + 8;
      quad[0].texCoords = Vector2f(x1, y1);
      quad[1].texCoords = Vector2f(x2, y1);
      quad[2].texCoords = Vector2f(x2, y2);
      quad[3].texCoords = Vector2f(x1, y2);

3
General / Re: Issues with tilemap system
« on: January 29, 2022, 07:44:08 pm »
Are you initializing xIterator, yIterator to zero?

They're initialised in the header file, yes.

4
General / Issues with tilemap system
« on: January 29, 2022, 05:50:21 pm »
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.
Quote
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.

Pages: [1]