java – Libgdx Box2d TiledMap Scaling

I think I'm doing something completely wrong, but I just do not seem to handle the Box2d pixel-per-meter conversion. Currently I have a tiled map with an object plane that I want to use as a collision box. I have one class to turn the object plane into shapes, and another to turn the units into meters. The problem I have is that I can only get the boxes with the correct size on my card if the pixels are set to 1: 1 per meter.

In the constructor for my level class, I have the following to create all box2d objects:

World = new world (new Vector2 (0f, -9.8f), true);
MapObjects objects = map.getLayers (). Get (collisions). GetObjects ();
for (MapObject object: objects) {
if (object instance of TextureMapObject) {
continue;
}

Shape mold;

if (object instance of RectangleMapObject) {
shape = ShapeFactory.getRectangle ((RectangleMapObject) object);
} else if (object instance of PolygonMapObject) {
shape = ShapeFactory.getPolygon ((PolygonMapObject) object);
} else if (object instance of PolylineMapObject) {
shape = ShapeFactory.getPolyline ((PolylineMapObject) object);
} else if (object instance of CircleMapObject) {
shape = ShapeFactory.getCircle ((CircleMapObject) object);
} else {
continue;
}

BodyDef bodyDef = new BodyDef ();
bodyDef.type = BodyDef.BodyType.StaticBody;
Body body = world.createBody (bodyDef);
body.createFixture (Form, 1);

shape.dispose ();
}
BodyDef bodyDef = new BodyDef ();
bodyDef.type = BodyDef.BodyType.DynamicBody;
bodyDef.position.set (x, y);
Body body = world.createBody (bodyDef);

FixtureDef fdef = new FixtureDef ();
PolygonShape-Shape = new PolygonShape ();
shape.setAsBox (16,16);
fdef.shape = form;
fdef.density = 1.0f;
fdef friction = 0.3f;
fdef restitution = 0.6f;
body.createFixture (fdef);


debugRenderer = new Box2DDebugRenderer ();

This invokes methods in my shapeFactory class that convert MapObjects to shapes.

Package Utils;

import com.badlogic.gdx.maps.objects.CircleMapObject;
import com.badlogic.gdx.maps.objects.PolygonMapObject;
import com.badlogic.gdx.maps.objects.PolylineMapObject;
import com.badlogic.gdx.maps.objects.RectangleMapObject;
import com.badlogic.gdx.math.Circle;
import com.badlogic.gdx.math.Polygon;
import com.badlogic.gdx.math.Polyline;
import com.badlogic.gdx.math.Rectangle;
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.physics.box2d.ChainShape;
import com.badlogic.gdx.physics.box2d.CircleShape;
import com.badlogic.gdx.physics.box2d.PolygonShape;

public senior class ShapeFactory {

private ShapeFactory () {}

public static PolygonShape getRectangle (RectangleMapObject rectangularObject) {
return getRectangle (triangleObject.getRectangle ());
}

public static PolygonShape getRectangle (Rectangular rectangle) {
PolygonShape Polygon = new PolygonShape ();

Vector2 size = new Vector2 (
Physics.toUnits (rectangle.x + rectangle.width * 0.5f),
Physics.toUnits (Rectangle.y + Rectangle.Height * 0.5f)
);

polygon.setAsBox (
Physics.toUnits (rectangle width * 0.5f),
Physics.toUnits (rectangle.height * 0.5f),
Size,
0,0f
);

Return polygon;
}

public static CircleShape getCircle (CircleMapObject circleObject) {
return getCircle (circleObject.getCircle ());
}

public static CircleShape getCircle {circle} {
CircleShape circleShape = new CircleShape ();
circleShape.setRadius (Physics.toUnits (circle.radius));
circleShape.setPosition (new Vector2 (Physics.toUnits (circle.x), Physics.toUnits (circle.y)));

return circleShape;
}

public static PolygonShape getPolygon (PolygonMapObject polygonObject) {
return getPolygon (polygonObject.getPolygon ());
}

public static PolygonShape getPolygon (polygon polygon) {
PolygonShape polygonShape = new PolygonShape ();

hover[] vertices = polygon.getTransformedVertices ();
hover[] worldVertices = new float[vertices.length];

for (int i = 0; i <vertices.length; ++ i) {
worldVertices[i] = Physics.toUnits (nodes)[i]);
}

polygonShape.set (worldVertices);

return polygon shape;
}

public static ChainShape getPolyline (PolylineMapObject polylineObject) {
return getPolyline (polylineObject.getPolyline ());
}

public static ChainShape getPolyline (polyline) {
ChainShape chain = new ChainShape ();

hover[] vertices = polyline.getTransformedVertices ();
vector2[] worldVertices = new Vector2[vertices.length / 2];

for (int i = 0; i <vertices.length / 2; ++ i) {
worldVertices[i] = new Vector2 ();
worldVertices[i].x = Physics.toUnits (vertices)[i * 2]);
worldVertices[i].y = Physics.toUnits (vertices)[i * 2 + 1]);
}

chain.createChain (worldVertices);

R├╝ckholkette;
}
}

This also calls methods in my physics lessons that are converted from units to pixels:

Package Utils;


import com.badlogic.gdx.math.Vector;
import com.badlogic.gdx.math.Vector2;

public senior year physics {

public static final float PIXELS_PER_UNIT = 32f;

private physics () {}

public static float toUnits (float pixels) {
returned pixels / PIXELS_PER_UNIT;
}

public static vector toUnits (vector2 pixels) {
Return new Vector2 (toUnits (pixels.x), toUnits (pixels.y));
}

public static float toPixels (float units) {
Return units * PIXELS_PER_UNIT;
}

public static Vector2 toPixels (Vector2 units) {
return new Vector2 (toPixels (units.x), toPixels (units.y));
}
}

If My Pixels Per Unit is 1, it's a perfect match, but physics looks like it's huge.

Enter the image description here

But if my pixel per unit is 32, as I want it, it is far too small.
Enter the image description here