Jump to content
  • Advertisement


This topic is now archived and is closed to further replies.


Map drawing trouble

This topic is 6216 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi! I am very new to isometric tile drawing, and I have been having a hell of a time trying to get a draw map function to work correctly. I managed to get a rectangular tile map working just fine, but this one is escaping me (and I have read every article here on GameDev as well as some others such as chapter 12 from the book at Isohex.net). Here is what I am trying to do: I am using 1:1 isometric tiles that are 44x44. What is really escaping me is the math in the FOR loops. I know it is supposed to be very simple but for some reason what I am using just isn''t working and rather than spend another 2 days running into the same problems, I figured I would ask here If anyone could please give me an example of something like this... I have read plenty of articles to know how its *supposed* to be done and that doesn''t work, so any code specifics would help trmendously Sorry if this sounds too "newbie"! Thanks in advance.

Share this post

Link to post
Share on other sites

Down at the bottom there''s a tutorial on figuring out the math for any ISO tile.

It should be easy from there.


Share this post

Link to post
Share on other sites
Well I got that part worked out... It draws the map fine but now I have another problem - that is smooth movement around the map. Right now for some reason the tiles JUMP as you move. I found how to fix that, but when I fix that is messed up my drawing boundaries! Here is the code I am using, maybe someone can figure out where I am going wrong...

bool DrawTiles()
int x, y, i;
RECT rcDest;
BYTE byTile;

// Tile location of the upper left corner of the screen

int xStart = mapData.xScreen / 44; // xScreen is the pixel coordinate for movement

int yStart = mapData.yScreen / 44; // yScreen is the pixel coordinate for movement

// Set the RECT of the first tile to be drawn

rcDest.left = xStart * 44 - mapData.xScreen;
rcDest.top = yStart * 44 - mapData.yScreen;
rcDest.right = rcDest.left + 44;
rcDest.bottom = rcDest.top + 44;

RECT rcTemp = rcDest; // Will need a backup!

for(x=0; x<30; x++)
// if we are on an odd row, i will be TRUE

i = (x+2)%2;

// increment the RECT for the next tile

rcDest.top += 22;
rcDest.bottom += 22;
rcDest.left = rcTemp.left;
rcDest.right = rcTemp.right;

// offset the RECT and tile coord for an odd row

yStart += 1;
rcDest.left -= 22;
rcDest.right -= 22;
// on an even row, increment the coord down 1 full tile

if(x > 0)
xStart += 1;

for(y=0; y<18; y++)
// current tile coords being drawn

xCurr = xStart + y;
yCurr = yStart - y;

// increment the bounding RECT

rcDest.left += 44;
rcDest.right += 44;

// make sure we arent drawing past the map limits

if(xCurr >= 0 && xCurr <= mapData.xMax && yCurr >= 0 && yCurr <= mapData.yMax)
// this is just a makeshift linked list for testing, it works for now

i = mapLoc[xCurr][yCurr].nNumTiles-1;
byTile = mapLoc[xCurr][yCurr].tileData[i].byTile;

// if there is a tile in that spot, BLT it!!

if(byTile > 0)
g_pDDSBack->Blt(&rcDest, mapData.pDDSTileset, &lptileInfo[byTile]->rcLocation, DDBLT_WAIT | DDBLT_KEYSRC, NULL);

return true;

Excuse me if it looks a little sloppy, I am trying to get it WORKING before I go optimize every little detail

As you can see, mapData.xScreen and mapData.yScreen are the pixel coords of the map, and somewhere between that and the starting RECT are where I think my problems are...

Thanks in advance

Share this post

Link to post
Share on other sites
If anyone feels like they might be able to help, i can post the program and show what it is doing, just let me know! please!

Even if there is another way entirely to do this math... Thanks!

Share this post

Link to post
Share on other sites

This answer comes maybe a little bit too late, if not well just read it.

You have to check if your position in the world can be devided by 44 (since you have 44*44 tile). If it is then you can display the full tile. If not you have to "slide" the RECT to display a part of the tile. How much? the result of the previous division.

I think this should work, you should have a smooth movement.

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!