title: Mouse coordinate conversion Libgdx
body: <p>I have a camera:</p>
  
  <pre><code>//Map is a my object that wrapper of TiledMap class
  </code></pre>
  
  <p>In the create method:</p>
  
  <pre><code>this.renderer=new OrthogonalTiledMapRenderer(this.map.getMap();
  this.camera=new OrthographicCamera();
  this.camera.translate(map.getMapPixelWidth()/2, map.getMapPixelHeight()/2);
  this.camera.update();
  view=new StretchViewport(map.getMapPixelWidth(),map.getMapPixelHeight(), camera);
  batch=new SpriteBatch();
  </code></pre>
  
  <p>In the update method:</p>
  
  <pre><code>this.renderer.setView(this.camera);
  this.renderer.render();
  this.camera.update();
  batch.setProjectionMatrix(camera.combined);
  
  ArrayList&lt;RectangleMapObject&gt; layer=this.getObjectsFromLayer("collision");//find collision layers
  //Mouse coordinates
  int x=Gdx.input.getX();
  int y=Gdx.input.getY();
  Vector3 coordinateScreen=new Vector3(x,y,0);
  Vector3 coordinateWorld=camera.unproject(coordinateScreen);
  Rectangle rectMouse=new Rectangle(coordinateWorld.x,coordinateWorld.y,20,20);
  for(RectangleMapObject rect: layer)
  if(Intersector.intersectRectangles(rectMouse, rect.getRectangle(), rectMouse)){
                      System.out.println("COLLISION MOUSE-MAPOBJECT ");}
  
  
  public ArrayList&lt;RectangleMapObject&gt; getObjectsFromLayer(String layerName){
  
          ArrayList&lt;RectangleMapObject&gt; array=new ArrayList&lt;RectangleMapObject&gt;();
  
          MapObjects og=this.map.getMap().getLayers().get(layerName).getObjects();
  
          for(MapObject object : og)
              if (object instanceof RectangleMapObject) 
                  array.add(((RectangleMapObject) object));
          return array;
  }
  </code></pre>
  
  <p>My problem is that the collision between mouse and mapobject never occurs Also if I click on the area where stands the MapObject.
  I think it is a problem of conversion of the coordinates of the mouse.
  Thank you for your time.</p>