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 making a tiled based game, I want not to let the camera show places, where there is no map... this is a obvious solution I got from a tutorial

}else if(camera.position.x>map.width*map.tileWidth-400){

}else if(camera.position.y>map.height*map.tileHeight-240){


but I don't know how to get width & height of the tiledMap in the latest version of libgdx

Seems strange... I even tried the Super classes but couldn't find. Please help.

share|improve this question
up vote 13 down vote accepted
TiledMap tiledMap = new TmxMapLoader().load("path/to/tiled/map.tmx");   
MapProperties prop = tiledMap.getProperties();

int mapWidth = prop.get("width", Integer.class);
int mapHeight = prop.get("height", Integer.class);
int tilePixelWidth = prop.get("tilewidth", Integer.class);
int tilePixelHeight = prop.get("tileheight", Integer.class);

int mapPixelWidth = mapWidth * tilePixelWidth;
int mapPixelHeight = mapHeight * tilePixelHeight;

The mapWidth and mapHeight are the dimensions of the map in tiles. So they would both be 10 in a 10x10 grid. The tilePixelWidth and tilePixelHeight are the dimensions of the tiles in pixels. In a 32x32 tileset they would both be 32. Multiplying the dimensions together you will get the map dimensions in pixels.

share|improve this answer
Hi there, mobo! Could you explain a little bit more about the snippet? It might help others. – Vaughan Hilts Jun 13 '13 at 14:05
MapProperties is just an Object map that holds any properties of the TileMap. If you are using a .tmx file its any of the properties in the first line: width, height, tilewidth, tileheight, orientation are all there by default. The cod was wrong and I am fixed it. – mobo Jun 13 '13 at 14:19
Thanks a lot - your contribution is appreciated I'm sure. :) – Vaughan Hilts Jun 13 '13 at 14:38
Thanks man, this helped me a lot :) – Rohwedder Jan 22 at 21:15

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.