LibGDX Tilemap Rendering

Hi,

I’ve been looking for the correct and performance-friendly method of rendering Tiled Maps. I am specifically wanting to know how to cull them with the Orthogonal Tiled Map Renderer.

Thanks!

  • A

Edit * I know how to render them on screen. This post is regarding camera culling.

You are creating many topics that already have answers or you can easily find on the internet, tutorials, videos or in libGDX wiki.

Neither of those post have my answer. I’m looking for a way to include camera culling with a Tiled Map renderer. I know how to render tile maps.
I do search, but with the little documentation LibGDX has on TiledMaps its difficult to find a good preforming method.

Best way to render tile maps: Tessellation or Offsetting a texture in the shader, and for sure: Texture atlases. (LibGDX doesn’t do that unfortunately)
Best way to parse tiled map editor maps: They’re in XML, export one and open it with notepad.

As for culling, you’ve just gotta check if the tiles are colliding with a box the size of your orthogonal proj. matrix. To do that create a subclass of tiled map and check if the tiles are colliding with the projection matrix just before rendering, and if not, don’t draw them. (But always always update them!)

The first link has the answer to your problem (haven’t bothered to look at the second one).

I strongly suspect that the map renderer takes care of the culling for you when you set the view bounds.

Yea, my bad. I assumed that when he linked it he was referring to getting the tile maps to display. Now, and this could be because I’m tired and its late, but I’m having trouble grasping the concept of setting the view port to follow the player.

Essentially, I need to have StartX, startY, endX, endY to both A.) fit the view port… and B.) follow the player.
Any ideas?

	float x0, y0, x1, y1;
		x0 = cam.position.x - Gdx.graphics.getWidth();
		y0 = cam.position.y - Gdx.graphics.getHeight();
		x1 = cam.position.x + Gdx.graphics.getWidth();
		y1 = cam.position.y + Gdx.graphics.getHeight();
		
		renderer.setView(cam);
		renderer.setView(cam.combined, x0, y0, x1, y1);

Nevermind, I figured it out for StartX, StartY, endX, endY… I think. while it is culling it out, it may not be the correct region…

Should be .getWidth() / 2 and .getHeight() / 2

Also, maybe Tiled map renderer wants tile positions? In which case you also need to divide these coordinates by tile size.