Jump to content

  • Log In with Google      Sign In   
  • Create Account

Banner advertising on our site currently available from just $5!

1. Learn about the promo. 2. Sign up for GDNet+. 3. Set up your advert!


Member Since 09 May 2012
Offline Last Active Oct 13 2012 03:50 AM

Topics I've Started

Iterate over TileLayers(Vector) doesn't work

28 July 2012 - 08:30 AM

Hi guys,

I have a (in my opinion) strange problem:

I am working on a 2D TileMap with multiple layers. It needs multiple layers because a Terrian-Transmission is a smaller Tile, laying on top of a normal Tile.

The Map, is a Vector of Tile-Vectors.
A Tile is a set of 2 Integers: TileID is ID inside TileSet, TypeID is Tile Type in game (NORMAL/NONE/WALL).

Now this is the code of my render() function:

int TilesetWidth  = Surf_Tileset->w / TILE_SIZE;

std::vector<std::vector<myTile> >::iterator it;
it = TileList.begin();

for (int Y = 0; Y < MAP_HEIGHT; Y++)
  for (int X = 0; X < MAP_WIDTH; X++)
   std::vector<myTile>::iterator tmpIt;
   tmpIt = it[X+(Y * MAP_WIDTH)].begin();
   int tX = MapX + (X * TILE_SIZE);
   int tY = MapY + (Y * TILE_SIZE);
   int TilesetX = (tmpIt->TileID % TilesetWidth) * TILE_SIZE;
   int TilesetY = (tmpIt->TileID / TilesetWidth) * TILE_SIZE;
   for (; tmpIt < it[X+(Y * MAP_WIDTH)].end(); tmpIt++)
	if (tmpIt->TypeID == TILE_TYPE_NONE || tmpIt->TypeID == TILE_TYPE_ERROR)
	 applySurface (Surf_Display, Surf_Tileset, tX, tY, TilesetX, TilesetY, TILE_SIZE, TILE_SIZE);

It should iterate about every Tile-Vector, calculate the screen position, and blit all tiles inside the vector that are not of type ERROR or NONE.

But instead of this it shows the first tile of every vector, nothing else. (I can choose the layer being drawn by setting tmpIt = ...begin() + x; )

So my question is: why does my iterator not iterate?

I have no idea why this isn't working...

Thanks for every help;).