Continuous 2D Worlds using chunks and rendering.

Hello everyone,

I could use some help and hopefully someone here can put me on the right path.

My overall goal, is I want stream 2D world chunks to client machines. I can do the networking, but I am having a problem figuring out how to render the world as the player travels through it. I can write a loop to get exactly what tiles to display, but I don’t know how to render these tiles. I have looked at the source of map renders in LibGDX and most parts of the code I don’t understand. It looks like the renderTileLayer does some sort of 3D work, but I don’t know anything about 3D to fully understand what is going on.

If someone can point me in the right direction to achieve this effect that would be greatly appreciated! :slight_smile:

I’m not familiar with libgdx but you could write your own tile renderer to draw the tiles directly using the libgdx graphics drawing commands. Often it’s easier to roll your own code rather than learning someone else’s heavily abstracted general purpose code. That being said, libgdx is held in high regard.

The usual way to quickly render tiles is to figure out where your player is in tile coordinates and then calculate the tile coordinates of a corner of the screen, then render that tile and all the rows and columns from that corner to the opposite one in a big rectangle. Then you won’t waste processor time drawing non-visible off screen tiles.

The libgdx code looks to be doing just that, but with some extra vertice flipping going on which is probably just an optimisation to draw a quad in some other orientation to what is stored in the sprite sheet in an efficient way that requires no additional sprite textures to be stored in VRAM.

Hello, unenergizer,

About your link, it’s about TWO-D graphics using a map format made with the software Tiled.

Regarding you doubt, render a map is quite easy, you just need to walk through the 2d array rendering each element. This can help:

And to make the map move with the player, you will need a camera. Just need to move the camera as the player moves.