1
\$\begingroup\$

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?

\$\endgroup\$
5
  • 1
    \$\begingroup\$ 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! \$\endgroup\$ Jun 19, 2013 at 2:38
  • \$\begingroup\$ 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? \$\endgroup\$
    – kraze
    Jun 19, 2013 at 2:50
  • \$\begingroup\$ 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 ) \$\endgroup\$
    – Sidar
    Jun 19, 2013 at 7:13
  • \$\begingroup\$ 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. \$\endgroup\$
    – Phil
    Jul 19, 2013 at 11:48
  • \$\begingroup\$ @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 \$\endgroup\$ Jul 19, 2013 at 15:27

1 Answer 1

1
\$\begingroup\$

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.

\$\endgroup\$
1
  • \$\begingroup\$ "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. \$\endgroup\$ Jul 19, 2013 at 17:57

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .