Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am developing a game in Java. 2D Fighter, Kind of like the 2d flash game Raze( I currently am using the Slick 2D game library and am researching how to structure my levels. I am currently stuck on the problem of the level format(e.g. file format). How do you structure a 2d level with collisions etc.?

Level Notes: Will go up down left right

NOTE: New to gamedev

share|improve this question
You basically asked this already:… – bummzack Aug 10 '11 at 7:58
up vote 1 down vote accepted

There are many ways of structuring 2D levels.

One way would be to create a Level class which contains all the GameObjects and their physics-related information. It would know of where each GameObject and its rotation, along with each GameObjects physics bounding shape its orientation. Then, you could create an editor for the Levels and let it save/load Levels using serialization or some other method.

The file format doesn't really matter, as long as it suits your needs. If you don't need to be able to edit it from outside an editor, you could just use serialization. If you do, then you can use a text file that describes all of the GameObjects that your Level contains. For example, your file format could be like this:

<Level name="Tutorial">
    <GameObject name="Floor1">
        <Physics type="static" shape="Box(1000, 10)"/>
        <Orientation position="0, 800" rotation="0"/>
    <GameObject name="Bob the Unicorn" class="">
        <Physics type="dynamic" shape="Polygon({10, 20},{40, 30},{-10, 500})" mass="99"/>
        <Orientation position="50, 30" rotation="50"/>
share|improve this answer
Check out mrohlf's answer. Using Tiled Map Editor's format is probably better than creating your own format. – skyuzo Sep 12 '11 at 20:17

Check out the Tiled Map Editor. It's a fairly flexible and user-friendly program, and Slick natively supports its file format, which makes it very easy to use.

You will want to have at least two layers in your map: one with the map graphics, and one collision layer (which won't be displayed in the game). When the player tries to move into a new tile, check the collision layer to see if a tile exists there, and if so, block the player from moving into the tile.

If you want to use arbitrary terrain shapes, you'll have to use something more like skyuzo suggested. Tile maps are less flexible, but they can still allow for a large variety of levels, and they're easier to work with as a beginner.

share|improve this answer

Your Answer


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.