Archived

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

Height map -> Tile map

This topic is 6012 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

Hello ev''ry1! So, I generated a height map. How can I transform it into a map of tiles? 4 example, height values with less than a Number, represent water, and greater then Number -- land. Need 2 build a cost line. TIA

Share this post


Link to post
Share on other sites
What exactly is a height map? Do you want to know how to transform numerical data into tiles printed on the screen? If so, there''s a great tiling tutorial here at gamedev, just search for it...

Share this post


Link to post
Share on other sites
Height map in my case is an array 256x256 of byte, each of which stands for height of terrain.
I need to know, how to transform height value into TileID, taking into account height value of given point and its eight neighbours. TileID is an index to tile data, and tiles are pictures, they may look like "Water on North & East, all other is ground"
There probably are such alorithms, but i can''t see how to do it without if...then senteses (they would look ugly and the code isn'' fast enough.

Share this post


Link to post
Share on other sites
OK, I see what you mean. So basically you want to draw a certain tile based on its tile ID. So what you want to do is the following:

This is assuming that you have a 256*256 char array.
Do a loop that goes through the first row of 256 values
Check the value in the array
Do a ''Select Case'' (I''m a VB programmer), and based on the value, draw the tile you need, eg. Draw_Tile(water_east)
When you''ve gone through the first 256, increase the y value by 1 to go to the next row in your array.
Repeat the process from before
Do this 256 times (in a loop)

I hope that this sort of makes sense.

Let me know if it helped.
Alexander McAndrew


Here''s the code that helped me:

for ( int y_index = 0; y_index < 12; y_index++ )
{
for ( int x_index = 0; x_index < 12; x_index++ )
{
tile_dirt.x = 32*x_index;
tile_dirt.y = 32*y_index;
if ( map[x_index][y_index] != 0 )
Draw_Bob (&tile_dirt, lpddsback );
}
}

Share this post


Link to post
Share on other sites
I assume you know how to draw a tilemap given an array of tile IDs; you''re trying to transform a grayscale heightmap into an array of tiles IDs, right? If so, how you do this depends largely on what tiles you have. But what I would do is this. Simply create a preliminary tile ID map of grass, sea, sand, etc, ignoring border tiles, depending on what range of heights the corresponding heightmap pixel falls into. Then, cycle through this new map, and for each tile, check its eight neighbors. If all of the neighbors equal itself, then don''t change it. If one of its neighbors does not equal itself, however, change it to the appropriate transition tile. I guess the best way to do this is to determine a direction (NW, N, NE, W, E, SW, S, SE) and what two tiles to transition to (sand->water, dirt->grass, etc.), and then passes these three values to another function that returns a tile ID. This, I''m afraid, would be solved only by a long switch/case structure. The only exception would be if you had some sort of clever numbering system; that could simplify things.

Share this post


Link to post
Share on other sites
Yeah, thanx TerranFury!
Indeed, I''m gonna use the clerver-numbering system, as U wrote.
I''ve found an article here at GameDev.net, it concerns this topic: Terrain Transision (Available in the section about tile-based/isometric games). The method described there is very good, But in my case it is not too suitable due to my map size.
As I mentioned in my previous posts, I use 256x256 map. If I have a minimum of four layers, and if I have to use more than one tile just to represent background (as suggested in the article), it will be a real memory consumer
I''d rather have my tileset reduced to a real minimum of tiles. (the article says, use 32 and they may overlay over base tile.. see the article for details...)
Could I have only eight tiles (N,S,O,W,NW,NO,SO,SW) for each pair of terrain (water-sand, sand-grass etc.)? Yes I know I can, but what do you think? would it be too ugly? too simple?
By the way, does any1 know if there are free tilesets available on the web and where?

Share this post


Link to post
Share on other sites