Skip to main content
GameDev.net gamedev.net
🔒 Locked

bitmaps as tile map files

Started by nex7 Mar 7, 2005 at 9:24 PM 10 replies 2.5k views
Original Post
nex7
nex7
im looking to create a file format for my engine and i thought about just using a bitmap...or some other image type... since each pixel would contain 3 layers (r g b) you could easily make a 3 layer map out of it... im just looking for the best way to safe my maps. thanks.
evillive2
evillive2
A bitmap can be a great way to store a map file but it can also be limmiting. For example, if you were to use each RGB color component as a tile index for a different layer, then you limit yourself to 256 tiles. When working in 2d the number of tiles can greatly exceed 256 quickly just from terrain transitions ( see this great article for some ideas *click*here*click* ).

Ultimately you will eventually want to make your own map file format to suit your own needs. I know it isn't what you want to hear but you will eventually get tired of being tied to someone elses ideas of what is important.
Evillive2
nex7
nex7
what format do you suggest?
markr
markr
Yes, an image would work pretty well, as mentioned above, this limits you to 256 tiles unless you do some post-processing.

It's probably better to have the layers as separate layers in your paint program, then save them out into separate files before you load it in (Photoshop, GIMP formats etc, are not going to be easy to read programmatically)

Plus if you want stuff like terrain transitions, I'd go for having some sort of post-processing which automatically assigns tiles which are adjacent to other specific tiles.

You could also have more than one pixel per tile, for example, 4 px per tile, then your code can automatically place edge / corner tiles on things.

Mark
Foot Soldier
Foot Soldier
Or you could have one bitmap as one mapfile, and have corresponding bitmaps for extra layers. I won't even start on how to organize all this, but it's just a thought.
Sure is a big 'ol world.
nex7
nex7
think im just going to go with writing binary data out....it would have been neat to load up a BMP into pain and just start throwing colors down and make a map. :)
evillive2
evillive2
Quote:
nex7: think im just going to go with writing binary data out....it would have been neat to load up a BMP into pain and just start throwing colors down and make a map. :)

This is not a half bad idea that I myself have been toying with but I am guessing that it is slightly different than how you are thinking. I was thinking that for making large landscapes (a world map) I could use paint or any other bitmap manipulation program to create a bitmap where green pixels are grass, blue water etc. instead of a randomly generated one that needs lots of touchups or a painstakingly detail oriented one done entirely by hand in a map editor.

Consider this for a second. Using 32x32 tiles on a 640x480 screen you get a 20x15 tilemap per screen. Lets say for arguments sake we have 8 screens wide and 6 screens down (larger than it sounds but still somewhat small). That is 48 screens of hand placing 300 tiles per screen or 14,400 tiles all together. That doesn't even count transitions or details or item placement. In retrospect for a bitmap it would be as simple as filling in a 160x90 pixel image to generate the overall landscape. And then using the article I linked to above it would be a sinch to generate the transitions on the fly when loading the bitmap into your map editor. By that time all you have left to do is place the details and items saving you a lot of work. Hehe, I say that as if it isn't still a lot of work but it really is anyway, however like I was saying, I think this can be a huge time saver.
Evillive2
nex7
nex7
yeah i think it would be really easy to come up with the overall map..then you would still need an editor to really add the detail you wanted.
Dale
Dale
Hi, thought I'd add my comments. :)

I've seen a method where one pixel colour can determine height, wetness and features (buildings, trees, roads, etc).

Basically, you have three channels: Red, Green Blue.

Red = height (256 different heights)
Green = wetness (256 levels of wetness)
Blue = features (256 buildings/trees/roads etc)

After loading your bitmap read off the pixels and with post-calculation you can form your map.

For example:
- Height:
1. Height 0-20 = sea level (then you can have shallow and deep seas)
2. Height 100-200 = "hilly" terrain (obviously assign a hill graphic here)
3. Height 200+ = "mountainous" terrain (you could say over 225 = "perma-snow")

- Wetness:
1. Wetness 0-50 = "dry" or desert conditions.
2. Wetness 50-150 = "normal" conditions.
3. Wetness 150-200 = "wet" conditions (jungle, marsh, whatever).
4. Wetness 200+ = "river" conditions (225+ = large river).

- Features:
This is as simple as assigning an element to each level (256 max). Zero is empty.

In this way, say you have a tile with RGB(152, 185, 204). This means the tile is height 152 (average hilly height) reasonably wet with 185 (rainforest maybe?) with element 204 on the tile which could translate to a gold deposit.

Dale
-----------------------------Empires! Visit online at http://www.daleszone.comProgramming for a funner world.
cairnswm
cairnswm
Or use 4bits for height (0-15), 1 bit for Wetness (water or not), and then you have 27 bits for items....
evillive2
evillive2
Using a bitmap file format for anything besides large map generation defeats the purpose I was talking about in the above post. Using a simple bitmap editor to plot pixels is much easier than plotting tiles in a map editor. For example, open up mspaint and create a 256x256 bitmap. Use the paintbrush tool to create a rough outline of what you want then use the pencil tool to enhance it a little (just a rough outline don't waste too much time) but don't zoom in at all. Use blue for water, green for land and brown for mountains. This is pretty simple right? Now zoom in to 800% and imagine creating the same overview map from this view with just the pencil tool. This is the difference I am talking about.

Just for clarity, I am not opposed to the suggestions above for using x bytes for tiles, and x for other data, I am just saying it is slightly different than the tool I was mentioning bitmap editors for. If you can get 8 different terrain types then a small 8 color pallete is very easy to work with when each color clearly represents a certain type of terrain and using the article above that I posted it generates the transitions for you saving boat loads of work. I guess what I am trying to say is tha the idea was not to use the .bmp file format to save map data but to help generate data from a .bmp file.

Ok, I am tired and need sleep and not sure if tha last bit made sense so I will stop now. Hopefully this still makes sense tomorrow.

Evillive2
Foot Soldier
Foot Soldier
I see what you wanted to do, but you could just make a brush tool in the map editor. You don't need to do each one individually.
Sure is a big 'ol world.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.