3
\$\begingroup\$

I am planning on making a 2D game, however different from my last personal projects I want this one to have enhanced graphics, with custom-designed levels. My previous 2d platformers were tile-based, in which I made a map editor for to create levels.

However, I am wondering the best way to implement custom designed maps? For say, some grass is a litter higher than others, flowers here and there, cool drawings and structures along the way, etc. instead of just the same old tiles over and over again. I am thinking but I just can't grasp the idea of how to implement it. I have seen it done in other games and am interested to see how they accomplish it, but can't get my hands on some source code. :(

\$\endgroup\$
7
  • \$\begingroup\$ You need to explain more about exactly what it is you're trying to achieve. \$\endgroup\$ Commented Jun 24, 2012 at 5:24
  • \$\begingroup\$ I want more customization in map creation than just tile-based, how is the best way of doing that? \$\endgroup\$
    – Qasim
    Commented Jun 24, 2012 at 5:26
  • \$\begingroup\$ That's usually called procedural graphics or procedural content generation. More details can be found here: pcg.wikidot.com \$\endgroup\$ Commented Jun 24, 2012 at 5:29
  • \$\begingroup\$ @Qasim: "I want more customization in map creation than just tile-based" That's not really narrowing things down. Be specific in what you're looking for. \$\endgroup\$ Commented Jun 24, 2012 at 6:45
  • \$\begingroup\$ @Qasim are you looking to implement a level system that has a higher precision than a tile-based system (i.e. pixel-perfect)? Or are you simply looking to make a tile-based system much more detailed? I have answers for both and more, but I am not quite sure what exactly you are asking. Perhaps you can provide examples of other games that use a system similar to what you are looking for? \$\endgroup\$
    – Apples
    Commented Jun 24, 2012 at 7:09

1 Answer 1

11
\$\begingroup\$

There are many different types of level systems, most of which are customized specifically for a single game. This answer will not cover every implementation detail of these systems, but rather an abstracted explanation of each.

Tile-based

Although most tile-based systems are very shallow and are incapable of supporting much detail, it is possible to overcome this. At the core, a tile-based system is a two-dimensional array of cells, each filled with a piece of data that details it's contents.

The first action most designers take to add detail to a tile-based system is to add layers. Layers allow you to have multiple grids of cells stacked on top of each other, giving you the opportunity to add things such as shadows and things that are raised vertically off the ground, such as the crown of a tree or a tall lamp post.

Also, most tile-based systems use tile sets. Tile sets are palettes of data that the level system can use to store tile information. This allows you to more efficiently support a higher number of tiles, because if you need more room, you can just add another tile set.

You can add detail to each tile via metadata. For example, you might have only one "grass" tile. Instead of making new tiles for each height of grass, you can simply add metadata that describes this height.

Arbitrary Placement Level

Although a bit more complicated than a tile-based system, an arbitrary placement system gives you free control over the location of objects. Basically, every object in the level is given a position, rotation, and scale. So instead of having a list of cells that contain objects, you now have a list of objects that contain positional data.

Since each object contains it's own set of data, it is possible to store graphical information for each object. For example, instead of using a tile set to store the graphics for each type of tile, each object can now contain unique graphical data, such as the name of an image file.

Because the objects can intersect with each other, you will need to give each tile (along with it's X and Y position) a Z position, which is essentially it's layer. Objects with a higher (or lower, if you choose) Z position are drawn last, so that only the most prominent objects are shown on top, and all background objects are drawn behind these.

Arbitrarily placed objects can also have arbitrary sizes, allowing you to specify a long stretch of grass as one object, instead of have several tiles stored in several cells. Thus, an arbitrary placement system uses less memory than a tile-based system (usually). Also, things other than terrain may be stored in the level data, such as enemy placement, dynamic lights, and events. Although it is possible to make a tile-based system that included these features, it is almost certainly more difficult.

Conclusion

As you can see, both tile-based and arbitrary placement systems have their advantages, so it might be hard to choose between them. However, there is no reason you cannot have both. You can make a tile-based system as the base, and store all of your basic terrain in that, and then you can specify an arbitrary placement system on top of that, for adding objects that cannot be represented in a tile-based system.

In the end, the only way to get more detail into a level system is to force it in. Add more layers and tile attributes to your tile-based systems, and overlay an arbitrary placement system on top of that for the fine details.

\$\endgroup\$
3
  • \$\begingroup\$ Wow, that was a long answer. Does anybody have any suggestions on how I can cut down on the size? \$\endgroup\$
    – Apples
    Commented Jun 24, 2012 at 7:59
  • \$\begingroup\$ It was an excellent summary of the two types of level systems mentioned, and looks to be at an appropriate length. Thanks for the help. \$\endgroup\$
    – Qasim
    Commented Jun 24, 2012 at 13:57
  • \$\begingroup\$ No problem. I wish I could give you a more concrete answer, but the subject has more to do with artistic design than actual programming. \$\endgroup\$
    – Apples
    Commented Jun 24, 2012 at 19:53

You must log in to answer this question.

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