2D Isomentric maps.
Hey there...
Im trying to create a 2d isometric map based on an array(m_iMap[MAP_WIDTH][MAP_HEIGHT]). My tile size is 64x32... Im having trouble with the code. So far all i can come up with is:
for(int w = 0; w < MAP_WIDTH; w++)
for(int h = 0; h < MAP_HEIGHT; h++)
{
g_pGrassBitmap->Draw(hDC,xPos + TILE_WIDTH * w,yPos + TILE_HEIGHT * h,true);
}
But it gives me the tiled effect with gaps in between. Heres a silly diagramme! ^^
--------------------------
# = Tile
* = No tile
#*#*#*
*#*#*#*
#*#*#*
-------------------------
lol. i hope that makes sense. I know that code snippet is incorrect but i cant think of how to fix it.
PLEASE HELP!!!
Thanks
Each odd-numbered row needs to be shifted half the tile width to the right, and the rows are only half the tile height below the one above.
Don't you want it to be:
Keep in mind that
1 + 2 * 3
is not equal to
(1 + 2) * 3
because multiplication has a higher priority than addition ;)
g_pGrassBitmap->Draw(hDC, (xPos + w) * TILE_WIDTH, (yPos + h) * TILE_HEIGHT,true);
Keep in mind that
1 + 2 * 3
is not equal to
(1 + 2) * 3
because multiplication has a higher priority than addition ;)
mmmm.. That doesnt work.
Basically, i have to move every second row a 1/2 tile to the right and a half a tile down and then move the next row back again. But i cant figure out how :-( Im so frustrated... It shouldnt be this hard...
Basically, i have to move every second row a 1/2 tile to the right and a half a tile down and then move the next row back again. But i cant figure out how :-( Im so frustrated... It shouldnt be this hard...
Use the % (modulus) operator
// modulus (divides, and returns remainder)const int rowOffset = (h % 2) ? (TILE_WIDTH/2) : 0;// or check the LSB (faster)const int rowOffset = (h & 1) ? (TILE_WIDTH/2) : 0;
Quote:Original post by _damN_
Kewl!!!! Thanks it works beutifuly... But why is the one faster than the other? :-/
One calculates remainder after a divide by two, while the other is just a bit compare.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement