Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I've been developing a very basic 2D tile-based game for my own experience. I read what must be hundreds of tutorials on what I found on Google with "tile based maps".

Almost every tutorial I see is an engine that reads a text file and loads tiles based on the numbers in the file, such as:

0,0,0,0
3,0,0,3
2,0,2,2
2,0,2,2

But what if I were making a map that contained several 100 tiles?

surely there's an easier way to make a map than by writing a ton of numbers into a text file? How can this be done quicker?

An idea I had was making the world a single layered image: A layer for the objects/sprites/characters and another on top of that for tiles that should be under you like walls, trees, etc.

Is this possible/worthwhile?

share|improve this question
1  
Almost all tiled maps are created with special editors that let you "paint" with tiles as brushes, and have lots of built in helpers to make the job easier. There's definitely not a lot of writing text files except for very small test maps. Search google on "tile map editor" for a good overview and lots of examples of these kinds of editors! –  Patrick Hughes Jun 19 '13 at 2:38
    
thanks for your reply mate, yeah right now i'm currently using tiled. but most loaders i've looked at have very little explanation of how they work and i gave up figuring them out, right now i use Tiled to make the map, save it as a image and add it onto XNA.. that way i just use a single image as the entire map, ill be putting a grid over the top, add invisible collision tiles and then a layer on the top of that for eg top of trees and walls that the character goes under when moving over the top of the tile.. is this possible and/or a viable way of mapping? –  kraze Jun 19 '13 at 2:50
    
You seem to be concerned with the by the size of your text file. Don't, just have something working and see if there is anything to improve ( regardless though, your map size will always grow the bigger your level is ) –  Sidar Jun 19 '13 at 7:13
    
Your idea of the image is one that pops up often, and is useful, because if you do it right, you've instantly got the map for your game already coded! The catch is, that if you're writing pixel data with RGB values, then essentally all you're doing is saving a 6 digit hex number instead of a single "Index" number as you've been finding. The principle is identical, with many of the same hurdles. Both are useful. Most maps for 2D games are going to be one or more layers of ID numbers as you've found. You can shrink them using compression such as Run-length encoding or LZH or anything else. –  Phil Jul 19 '13 at 11:48
    
@kraze The image idea scales incredibly poorly. The maximum size of a texture is around 8k by 8k and most cards can only handle 2k by 2k. Whats wrong with saving it as a .tmx file and loading that in? bitbucket.org/vinull/xtiled –  ClassicThunder Jul 19 '13 at 15:27

1 Answer 1

When you handcraft the map you probably want some kind of map editor. When it is for learning (and otherwise too), I would recommend to make your own editor. That way you discover what difficulties is involved and you can make a perfect fit for your particular use case.

When storing the map you might want to save more than just the tile id, so in the end you probably have to come up with your own map/save format.

And just to keep your options open, here is an alternative approach:

  • "Procedurally generate" the map instead of handcrafting it. The maps are generated from a "pseudorandom seed" (just a long integer number), so all you need to save is the seed and any eventual changes to the generated map.

  • For map and game state storage, use an embedded database like SQLite instead of files. This way you can make advanced queries against your current map/game state.

share|improve this answer
    
"When storing the map you might want to save more than just the tile id, so in the end you probably have to come up with your own map/save format." Every single tile map editor allows you to define objects/polygons and add custom fields. There is pretty much no reason to create your own tools or format unless you are getting exotic. –  ClassicThunder Jul 19 '13 at 17:57

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.