Approach to mapping 2d tiles?

Started by
7 comments, last by nfries88 8 years, 1 month ago

Here is what we are looking at doing. We are making a retro style game using sprite sheets. In our code we have it set up so that the world map rendering uses an image to define the placement of tiles... in other words, based on the hexadecimal color on the image the tile rederer knows which tile to get from the sprite sheet and render in that location. For example: if I define the sprite in the upper left corner as being the hexadecimal color of 000000 (black) - anywhere I paint black pixels on the map image (where 1 pixel represents 1 tile in game), that sprite will be used when the game renders...

Ok, I hope that makes sense. I know this is a method that has been used for quite a while, and I know there are tile mapping programs... would you know of a tile mapping program that will allow me to define a hex color for each tile and then render a pixel map using those colors in place of the tiles?

Advertisement


would you know of a tile mapping program that will allow me to define a hex color for each tile and then render a pixel map using those colors

If I'm reading that correctly, it is as simple as opening up your favorite drawing program (or MSPaint) and zooming in. Colors will be nearly-black shades of blue, but should be distinguishable.

You might instead use an indexed color graphics format, such as gif, then assign a different color to each index. Maybe you've got 2 types of water tiles, indexed values 7 and 8, assign those two shades of blue. Then maybe you've got 6 basic dirt tiles, indexed values 1-6, assign those index values to shades of brown. Maybe index values 9-13 are tree tiles, assign those index values to shades of green. Etc.

Whatever you use for them, hopefully you're using a lossless graphics format. :-)

Alternatively, you any tile map editor, and convert its output to an image?

If you also build a reverse conversion, you can even consider the image as the primary tilemap description

Alternatively, you any tile map editor, and convert its output to an image?

If you also build a reverse conversion, you can even consider the image as the primary tilemap description

Yeah, I think OP may still be a little confused about data vs representation. Definitely moving in the right direction though. OP, what is it that you're actually trying to accomplish here? Can you give a more detailed explanation of what you want to happen from a user perspective? (I'm asking for what's called a "use case". I want you to tell me a story about using the tool you're imagining so that I can understand in fine detail what you want to see.)

It's fairly trivial to write a texture/tilemap converter if you're not using a really obscenely crazy format for tilemaps and not using a lossy format for textures.

void hurrrrrrrr() {__asm sub [ebp+4],5;}

There are ten kinds of people in this world: those who understand binary and those who don't.

I've seen similar formats, but not image based, just a text file, for example, 1-9 is the tile type, 0 is a blank tile, and you end up with something like:



1111111111111111111111111111
1000000000000000000000000001
1000000000222000000000000001
1000000000000000000033300001
1111111111111111111111111111

Do you mean something like this: http://www.mapeditor.org

edit - I misunderstood your question, what you're asking would be done by you the programmer with the tilemap data. I've never seen a map editor have something like that built-in. But lets say you have a byte represent what tile is visible at a location, use a lookup table with 256 entries, where each entry is a RGB value. Create an array of colors using the lookup table. Save image using your preferred method.

-potential energy is easily made kinetic-

To computers, numbers may be anything. And that's the only thing computer understands, numbers. It's what a program makes of those numbers. So, simply put, for a paint program, numbers may represent colors. For a text editor it may represent character codes. So basically you would just open that file in a tile map editor. The problems are the headers, if any, that the files have, and the format of your "colors".

It seems you are using 24 bit per color (perhaps even 32 bit if your program or color format aligns). 24 bit is over 16 millions possibilities (in your case, diffenrent tiles) And not sure you'll find tilemap editors that use 24 or 32 bit. Most will use 8 or 16 bit.

I once used a paint program to manipulate maps. I used an 8 bit palette image format. It was unintuitive and it also proved to be unproductive. Had to remember what each colors meant. And that's probably why you are here asking about this today.

Best for you would be to use any available tilemap editor that fits your need. A quick google search reveals quite a few free ones. Then adapt your program/game to the format that editor uses.

As for myself, what I ended up doing is write my own level editor and embedded it in my game.

Site: Hexmind.com Twitter: @HexmindGames Facebook: /hexmind Working on upcoming game, Reapertom.

I think that the idea might be to provide a simple method for players to create their own levels.

Typically with a tile editor, you're drawing the tiles to the screen so that you can see what the finished level is going to look like rather than create an abstract representation of the level. Maybe there's some existing program out there that does what you want to do but if I were in your shoes I'd write my own tool to do what you're looking for.

Or, a low tech option might be to print off a page showing the sprites and underneath indicate the respective colour values. Or maybe create some kind of word file with copies of the sprites that you can reference as you're drawing the level. In effect, this would be all there is to a tile editing program as you've described (if I understand your description). You would then need to add some code to your game to load the image file and translate the pixels to whatever tile or sprite index you want.


Ok, I hope that makes sense. I know this is a method that has been used for quite a while, and I know there are tile mapping programs... would you know of a tile mapping program that will allow me to define a hex color for each tile and then render a pixel map using those colors in place of the tiles?

Unfortunately most of them will only output a bloated general-purpose document instead of an efficient format like you're describing, although some of them claim to allow you to program the output somehow (I've never used them).
My advice: Take the bloated general-purpose document from a Tile editor and convert it into the more optimal raster image yourself. Also, please note that for most tilesets, an 8-bit integer will suffice (sometimes a 12-bit integer, which can be packed 2 into 3 bytes with bit ops).
Some of them are open-source. It might be worth just modding them (even if just for in-house use) to avoid that extra step.

This topic is closed to new replies.

Advertisement