title: Libgdx tiled map collision detection
body: <p>I am currently working on a 2d rpg game like final fantasy 1-4. Basically, my tiled map can be loaded and the sprite can walk freely on the map. </p>
  
  <p>How do I handle collisions with tiled map?</p>
  
  <p>I have created three separate tile layers. "Background Layer", "Collision Layer", "Overhead Layer" and I am not sure if this is useful or not..</p>
  
  <p>Edit: I have now created an object layer for collisions with rectangles over the areas I wanted the sprite to collide. </p>
  
  <p>Any help is greatly appreciated. Thank you!</p>
  
  <p>This is my current code</p>
  
  <pre><code>MapObjects collisionObjects = (GameAssets.mainTiledMap).getLayers().get("CollisionLayer").getObjects();
  int tileWidth = 16;
  int tileHeight = 16;
  
  for (int i = 0; i &lt; collisionObjects.getCount(); i++) {
      RectangleMapObject obj = (RectangleMapObject) collisionObjects.get(i);
      Rectangle rect = obj.getRectangle();
  
      rect.set(GamePlayer.x, GamePlayer.y, 16,16);
  
      Rectangle rectobject = obj.getRectangle();
          rectobject.x /= tileWidth;
          rectobject.y /= tileHeight;
          rectobject.width /= tileWidth;
          rectobject.height /= tileHeight;
  
      if(rect.overlaps(rectobject)) {
          GamePlayer.ableToMove = false;
      }
  }
  </code></pre>