I'm going crazy with this problem. I'll explain:
I have a camera that falls down (flowing along the y-axis) which displays a TiledMap and declare the whole in this way:
In the create method:
map=new TmxMapLoader().load("Map.tmx");
this.renderer=new OrthogonalTiledMapRenderer(map);
this.camera=new OrthographicCamera(Gdx.graphics.getWidth(),Gdx.graphics.getHeight());
this.camera.translate(Gdx.graphics.getWidth()/2,Gdx.graphics.getHeight()/2);
this.camera.update();
In the render method:
this.renderer.setView(camera);
this.renderer.render();
camera.position.y+=1;
camera.update();
Then I have also a sprite drawing by SpriteBatch in the render method:
batchM.begin();
sprite.draw(batchM);
batchM.end();
In the tiledmap there are MapObject and I have to check if this objects hit to sprite and I do this so in the render method:
MapObjects collisionObjects = map.getLayers().get("objects").getObjects();
for(MapObject object : collisionObjects) {
if (object instanceof RectangleMapObject) {
RectangleMapObject rect = ((RectangleMapObject) object);
Vector3 coo=camera.project(new Vector3(rect.getRectangle().x,rect.getRectangle().y,0));
com.badlogic.gdx.math.Rectangle Sprite= sprite.getBoundingRectangle();
com.badlogic.gdx.math.Rectangle Map=new com.badlogic.gdx.math.Rectangle(coo.x,coo.y,32,32);
//TEST
System.out.println("PLAYER X: "+Sprite.x+" Y: "+Sprite.y);
System.out.println("Object X: "+Map.x+" Y: "+Map.y);
if(Intersector.intersectRectangles(Sprite, Map, Sprite)) System.out.println("HIT");
} }
My problem is that when I do not change the window size(remain the size the starting), collisions are detected fine, but when I change the window size (for example, I enlarge) collisions are not detected and I can not explain why.
Could you help me to fix this bug. Thank you for your time