for(x = 0, x<WorldSizex, x++) {
for(y = 0, y<WorldSizey, y++) {
[/source]
This is way to slow, I need a way to only loop threw the tiles on the screen, I can''t figure out how because I tried to use a worldpos variable, but then I can only see 1/2 the map, the reason is because of this:
/\ <- 0,0 coordanite
/ \
\ /
\/
if I try to move left on the map, it has to minus 1 from world pos which was already 0, that means I have a negative, the loop wont work with negatives, what should I do?
Here is my funtion I use but doesnt work unless I loop threw the whole map.
[source]
for (int y = WorldPosy; y < WorldPosy + 20; y++)
{
for (int x = WorldPosx; x < WorldPosx + 20; x++)
{
timelooped++;
var1 = (y * -32) + ((x - WorldPosx) * 32);
var2 = ((y - WorldPosy) << 4) + (x << 4);
tile_dest.left = var1;
tile_dest.right = var1 + TILE_WIDTH;
tile_dest.top = var2;
tile_dest.bottom = var2 + TILE_HEIGHT;
if((tile_dest.left < (SCREEN_WIDTH)) && (tile_dest.left > -40) && (tile_dest.top < (SCREEN_HEIGHT - 170)) && (tile_dest.top > -50)) {
tile = map[x][y].tileID; // tile now stores the ID of this particular tile and the RECT
ddrval = lpDDSBack->Blt(&tile_dest, tilebmp, &tile, DDBLT_WAIT | DDBLT_KEYSRC , NULL);
map[x][y].tileposx = tile_dest.left;
map[x][y].tileposy = tile_dest.top + 41;
tilesblt++;
if(ddrval != DD_OK) {
MessageBox(main_window_handle, "Error: Couldn''t draw the map.", "Error", MB_OK);
PostQuitMessage(0);
}
}
}
}
return(timelooped);
}
Remember, this is a Isometric map, not a square tile map.
Well if someone could help me, I would like that.
Thanks,
James
Isometric Question.
Hey,
Well the problem I am having is this, I have to loop threw the whole map like this:
Well here''s what I do... to start off I got to variables MapTopX and MapTopY which specifies the number of pixels I am from the top left and right corners of the map. My map is in an array form so it''s easy to access with x and y positions.
So when I go to paint my screen I divide MapTopX (The numbers of pixels from the left of the map) by my tile width (68) and figure out how many tiles I am away from the edge of the map. That''ll be my starting X tile so I can skip every tile before that value and I only go to about 13 tiles past that value (However many I can fit in the screen) then skip everything after that and go on to my next horizontal row.
Now the Y tiles are a little bit trickier. I''m assuming your using isometric tiles so every tiles rectangle "overlaps" ther row above it by half and the row below it by half. In my game there is also a 1 pixel space between every second horizontal row and the tile are 33 pixels tall (an odd number, plus the 1 pixel space is 34) 34 in half is 17. So I divide MapTopY by 16 and that''ll be the number off tile to skip from the top and I only go about 31 tiles down from that (However many I can fit again)
Does this make sense?
Alright now the remainder from those two divisions gives me the offset of the whole map which is very important for smooth scrolling! So all of my tiles have this value add to added to them. Last but not least I subtract half of the tile width (34) from the x pos and half of the tile height from the y (17) pos.
This offset''s the whole map to avoid black spaces on the right.
Did that all make sense? Well there is a good tutorial by TANSTAAFL in the resource section entitled "Isometric and Hexagonal Tiles Part 1" or something close to that... you''ll find it. It does a better job at explaining tiling than me.
Good luck!
- Ben
P.S. If you can make heads or tails of my tiling method it works well! I can have an infinite map size limited to the amount of memory you have, but I also only use 4 bytes per tile in memory, I''ve test up to 256x256 tiles, and will be using 1024x1024 tiles probably for final levels and such...
So when I go to paint my screen I divide MapTopX (The numbers of pixels from the left of the map) by my tile width (68) and figure out how many tiles I am away from the edge of the map. That''ll be my starting X tile so I can skip every tile before that value and I only go to about 13 tiles past that value (However many I can fit in the screen) then skip everything after that and go on to my next horizontal row.
Now the Y tiles are a little bit trickier. I''m assuming your using isometric tiles so every tiles rectangle "overlaps" ther row above it by half and the row below it by half. In my game there is also a 1 pixel space between every second horizontal row and the tile are 33 pixels tall (an odd number, plus the 1 pixel space is 34) 34 in half is 17. So I divide MapTopY by 16 and that''ll be the number off tile to skip from the top and I only go about 31 tiles down from that (However many I can fit again)
Does this make sense?
Alright now the remainder from those two divisions gives me the offset of the whole map which is very important for smooth scrolling! So all of my tiles have this value add to added to them. Last but not least I subtract half of the tile width (34) from the x pos and half of the tile height from the y (17) pos.
This offset''s the whole map to avoid black spaces on the right.
Did that all make sense? Well there is a good tutorial by TANSTAAFL in the resource section entitled "Isometric and Hexagonal Tiles Part 1" or something close to that... you''ll find it. It does a better job at explaining tiling than me.
Good luck!
- Ben
P.S. If you can make heads or tails of my tiling method it works well! I can have an infinite map size limited to the amount of memory you have, but I also only use 4 bytes per tile in memory, I''ve test up to 256x256 tiles, and will be using 1024x1024 tiles probably for final levels and such...
__________________________Mencken's Law:"For every human problem, there is a neat, simple solution; and it's always wrong."
"Computers in the future may weigh no more than 1.5 tons."- Popular Mechanics, forecasting the relentless march of science in 1949
"Computers in the future may weigh no more than 1.5 tons."- Popular Mechanics, forecasting the relentless march of science in 1949
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement