Hello,
i start looking for some Box2D examples today and everything is working fine except that i don’t understand the creation of a simple rectangle inside Box2D (polygon), if am right the steps needed to create a box2D rectangle are the followings
BodyDef polygonDef = new BodyDef();
polygonDef.position.set(x, y);
polygonDef.type = BodyType.DynamicBody;
Body polygonBody = world.createBody(polygonDef);
PolygonShape polygonShape = new PolygonShape();
polygonShape.setAsBox(width, height);
fixture.shape = polygonShape;
polygonBody.createFixture(fixture);
and to create a Rectangle in libGdx we do this :
shapeRenderer.begin(ShapeType.FilledRectangle);
shapeRenderer.filledRect(x, y, width, height);
shapeRenderer.end();
now supposing i create a libGdx rectangle with the following coordinates :
x =100, y=100, width=100, height=100
in order to have a Box2D rectangle in the same position with the same size, i had to use the following coordinates :
x = 30, y=30,width=10,height=10;
i tried to figure out the relation between them but i didn’t succeed, i know that box2D use meters instead of pixels but what i don’t know is 1meter=??pixels, and how i can use Box2D with “simple” coordination
thank you