I'm sorry if this question has been previously answered, but I was unable to find an answer here or through google. I'm trying to make a simple roguelike-like that would feature a top-down tile map, a player, AI controlled enemies, and various items. I'm having trouble understanding how I can properly have the tilemap interact with the player and enemies through both collision detection and rendering.

It seems that the two main options for collision detection are 1)to specify if a tile is collidable in Tiled Map Editor, and then check tile by tile in the game code to see if the player's position overlaps that of a nearby collidable tile, or 2)integrate the tilemap with box2d physics. Admittedly, I do not understand any part of using tilemaps with box2d.

Additionally, I am unsure of how to properly draw the tilemap in reference to the player and enemies. Say I had a tree tile that I would like to always draw on top of/in front of the player. What is the best practice for accomplishing this in libgdx? I was thinking assign such tiles a certain ID and then render them after the player is rendered.


1 Answer 1


You can put the tiles you want to render in front of the player in its own tile layer, then you can draw that layer after you've drawn the player. The tiled map renderers in libgdx can take an int array as an argument that specifies what layers to render.

//create the int arrays
int[] background = {0};
int[] foreground = {1};

//in the rendering method
//drawing the player here

For collision detection you can take a look at this video and see if it answers your question: click me


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .