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'm creating a simple top down Zelda-esque game in libgdx, and I want to implement tile-based dungeons that are procedurally generated, similar to this.

Libgdx does have a class called TiledMap which would seem to fit my needs, however documentation outside of the official docs suggests that TiledMaps can only be used in conjunction with .tmx files, or in other words pre-designed maps. I've done a fair amount of Googling to no avail, so I'm asking here as a last resort hoping that someone has experience using libgdx for dynamically-generated tile maps.

edit: Could I use StaticTiledMapTiles in conjunction with the tutorial I linked to above to achieve my goal?


share|improve this question
Can't you write the data of the generated maps to a .tmx file and use that in LibGdx? – Dries Dec 28 '13 at 23:26
That's interesting. I suppose I could, although I feel like that wouldn't be ideal for quick generation. – camdenb Dec 30 '13 at 1:14

You can create tiled maps on without using .tmx.

TiledMap map = new TileMap();
MapLayers layers = map.getLayers();

TiledMapTileLayer layer1 = new TiledMapTileLayer(width, height, tile_width, tile_height);
Cell cell = new Cell();

cell.setTile(new StaticTiledMapTile(texture_region));
layer1.setCell(x, y, cell);


Each of these classes are in the docs for libgdx.
share|improve this answer
up vote 1 down vote accepted

Based on advice from /r/gamedev, I've decided to forgo the use of libgdx's TiledMap, etc. built-in classes and just build my own.

I can go into greater detail if requested, but here's what I've done, essentially.

1: Generate a dungeon using the algorithm I originally linked to, and store tile coordinates (not pixel coords) using a Coordinate class I made in a HashMap<Coord, MapTile>. MapTile is just a class that has data about the type of tile.

2: In the draw() function of my main class I added the following code

ConcurrentHashMap<Coord, MapTile> dungeonMap = dungeonGen.getMap();
        for(Entry<Coord, MapTile> entry : dungeonMap.entrySet()){
            Coord coord = entry.getKey();
            MapTile tile = entry.getValue();

            if((inCameraFrustum(coord.getX() * tileSize, coord.getY() * tileSize, 100))){
                        coord.getX() * tileSize, coord.getY() * tileSize);


Which iterates over every Coordinate in the dungeonMap and draws the tile (if the coordinate is in the camera frustum) with a global tileSize offset.

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.