Jump to content
  • Advertisement

Archived

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

graveyard filla

how to manage tiles in an RPG

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

high, im working on a 2d RPG using square tiles. im coming to the part of making a map editor, and i have so far only had 2 different types of tiles (wall or floor). now that i have to make a map editor, i will need to somehow make it so adding tiles will be as painless as possible. whats even harder is i have to figure out how to manage all these images/tiles. i cant just load all my tiles in at once because wouldnt that bog down the game badly? im using c++ and SDL so it will probably be software rendered.... so how do i manage which tiles to have loaded at any given time? ie when the map changes, i should free all my old maps images and load in the new ones? also, i would like to keep any tiles that are needed for the new map and not free them /reload them... i was thinking of making a tile something like (along with more info) struct Tile { unsigned int level_flags; } then pass it values like level_flags = CITYA|CITYB|TOWN3 ie each tile would know which map it was needed for. but im not quite sure how to implement it at all. how do i figure out which tiles to load, and even harder how do i figure out if an image is loaded in memory at any given time? hardest of all.. how in my map editor do i tell a tile which flags it has? would i have to hard-code each tile? thanks in advance for any help [edited by - graveyard filla on May 9, 2004 2:11:02 AM]

Share this post


Link to post
Share on other sites
Advertisement
I find that remembering that the image is just a representation of a tile and not THE tile can be helpful. I have my tile images broken up into groups: grass, dirt, water, castle etc. This makes it easier to only load the images you need. My tile class contains a pointer to a tile image class (basicly a derived class that handles drawing, animating etc.) which contains the information about the image. In the header of my map files I specify which tile image sets to use. I haven''t broken it down to check if it is already loaded cus I just dump the old ones. The time loading images between maps is trivial in my case but I can see where using large amounts of graphics would cause unwanted load time. Another handy thing to remember is that you can reuse the same "tile data" with different "tile images" to make different "tiles" as well as the other way around. I think what I am saying is that a tile is a combination of image and data. With only a few of each you can create many individual tiles.

Hope that made sense.

Share this post


Link to post
Share on other sites
When I was coding The Naufrago Project (here the homepage of the project) I solved the map question like this:

1) the map is an ascii file where every single letter is a cell (for example 0 -> sea, 1 -> grass, 2 -> rock)

2) a function load the file and read it char by char storing them into an array

3) when "rendering" the tiles I read the map array and I load the corrispondent tile... the tile images are stored with names that are ascii code so it's easy to know what to load.

In example: 0 is sea on the map file and its ascii code is 48, then the file 48.png will be the sea tile.

I hope I explained it well.

ciao,
dw

[edited by - dw on May 9, 2004 8:26:02 PM]

[edited by - dw on May 9, 2004 8:26:25 PM]

Share this post


Link to post
Share on other sites
dw,

thanks for youre reply. but im a little confused on what yoru talking about. you load in the image for each tile before you draw it? how could you keep reloading images like this? i think im just not understanding... also, how do you connect your array element (0) to ascii code and then load the image like that? i just cant put it all togeather... any help or example psuedocode is apprecaited. im lost right now and this is really holding up my game

Donkey Punch Productions.net

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
The memory load on a game is not too bad for a loaded tileset in memory. Personally I load the whole bitmap of tiles for a map when I load the map. By having the tile graphics in system memory the drawing is very fast, and since I use OpenGL for rendering the tiles have to be in system memory at some point anyway. Depending on the size of your tiles you can generally fit quite a few onto a single bimap and not have to worry about memory that much. For a 256 by 256 24-bit bitmap it only takes about 192kb of memory, and I can fit 64 tiles into a bitmap that size assuming they''re 32*32. When I load a new map I load in a whole new tileset specified for the map in it''s header. It''s not really a major load so the game doesn''t slow down at all. Actually setting up textures and perparing the tiles for drawing in OpenGL probably takes longer than the load itself.

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!