box2d – testPoint not working – libgdx

The problem I see is you are dividing the screenX and screenY values by 100 here:

if(fixture.testPoint(screenX/100, (mapHeight-screenY)/100)) { //100 is scaled parameter

screenX and screenY are the values indicating the X and Y coordinates of your touch and by sending a modified value to your testPoint method you’re not testing with the right values.

I suggest you send the original values to your testPoint method like so:

fixture.testPoint(screenX, mapHeight - screenY)

A couple of tips:

  • If you need a dragging behaviour check the onDragged method
    instead of the touchDown one.
  • If you are using an OrthographicCamera for your game (which is recommended) you don’t have to worry about wrong screen coordinates since you unproject the values to the correct ones and you don’t even have to worry about the Y axis being reversed, here’s an example:
OrthographicCamera camera = new OrthographicCamera(gameWidth, gameHeight); // gameWidth and gameHeight can be any float you want

public boolean touchDown(int screenX, int screenY, int pointer, int button) {
Vector3 unprojected = camera.unproject(new Vector3(screenX, screenY, 0f));
float x = unprojected.x;
float y = unprojected.y;
    for(Fixture fixture:bird.getBody().getFixtureList()) {
        if(fixture.testPoint(x, y) {
             draggedBird = true;
             return true;
         }
    }
    return false;
}