Creating a Box2D world of a certain size, whose viewport scales?

I have tried, but failed, to create a Box2D world of a specific size, which has a viewport that changes size based on the window size. I would like to have a Box2D body with a Box2D light attached to it that can move around like a person moving around a top-down flash light. I “sort of” worked out the moving problem, but this thread is for a different issue.

I need to know how to properly create the world and how to properly use the camera and PPM scaling so I can get a better understanding of how the coordinates work when changing from PPM to normal. Whenever I attempt this, my Box2D bodies look very small, and my backgrounds are extremely pixelated and zoomed in.

I didn’t want to post such a general questions, but I have tried at least four times, and the classes are building up in my project like “ScreenGame,” “ScreenGame1,” “ScreenGame2,” etc. I need some guidance, even if it is just suggestions of methods to try without code. Here is my code: https://gist.github.com/Elsealabs/84b4ab012a5adcdd42c8

I’d like something like this:

Use Viewport: https://github.com/libgdx/libgdx/wiki/Viewports


camera = new OrthographicCamera();
// use different viewports based on desired behavior on resize
viewport = new ScreenViewport(camera);
viewport.setUnitsPerPixel(1 / 32f); // 32 pixels per meter

// in resize()
viewport.update(width, height);

It is saying that the method “setUnitsPerPixel()” does not exist.

Edit: I fixed it, this method does not exist in “Viewport” but does exist in “ScreenViewport”