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 making a 2D game with libgdx, and I'm using its TileMapRenderer to render my map which I have made in the map editor Tiled. In Tiled I have a dedicated collision layer. However, I can't figure out how I'm supposed to hide it and its tiles in the game.

This is how a map is loaded:

TiledMap map = TiledLoader.createMap(Gdx.files.internal("maps/map.tmx"));
TileAtlas atlas = new TileAtlas(map, Gdx.files.internal("maps"));
tileMapRenderer = new TileMapRenderer(map, atlas, 32, 32);

Currently the collision tiles are rendered on top of everything else, as I see them in the map editor.

share|improve this question
up vote 6 down vote accepted

At this time, you'd have to create an int array of the layer indexes you do want to draw, and then use the render method which takes a camera and the layer indexes.

So, if you have three layers and the last one is the collision layer you do not wish to draw, you'd do:

int[] layers = new int[] {0, 1}; // preferably outside of the render loop, to avoid gc

then when you wish to render:

tileMapRenderer.render(camera, layers);

This is certainly less than ideal as the layer itself should have a visibility flag (as it does in tiled) which would be used to determine if the layer should be drawn as opposed to relying on whether or not the index is passed in to the render function.

I've been working on a new version of the Tiled module in LibGDX which hopefully will make it easier to work with.

share|improve this answer
Please add the TSX tile set support to ones :) And support to load unpacked maps for debugging/creating/testing purposes :) – asktomsk Nov 20 '12 at 13:15
@asktomsk : My working copy loads TSX files, so that'll definitely be in there. If you use SimpleTileAtlas you don't have to use the packer. Your mileage may vary, but I've not heard of there being any problems with that approach. – nEx.Software Nov 20 '12 at 13:30

Easiest way is to set the visibility to false tiledMap.getLayers().get(index).setVisible(visible);

EDIT: Reference to the libGDX API

share|improve this answer
Can you link to the documentation? Your answer suggests that the accepted answer is out-of-date, so a reference would be good. – Seth Battin Sep 14 '14 at 16:05
Thanks for the feedback, reference link added :) – Belfer4 Sep 14 '14 at 18:19

In Lua, I set the opacity to zero or the named layer, like:

if map.layers["collision"] then
   map.layers["collision"].opacity = 0

You need to search in libgdx how to get a layer by name, and then set its opacity.

share|improve this answer

You can also try hiding your collision layer by using this

TiledLayer collision;
// [...]

// search the collision layer
for(int i=0;i<map .layers.size();i++){
        map.layers.remove(i); // remove the collision layer.
share|improve this answer

The easiest way to do this it to simply not hide them at all. You should create a set of blank tiles on your PNG tile sheet. Use the blank tiles to create your collision layer and render it. Since all the tiles you use are transparent in nature, the image it writes is nothing.

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.