Hello!
I think I might have found a bug in LibGDX’s Box2D implementation.
I am loading a TiledMap in my game, and the objects that are on the map are added to the Box2D world with this function:
private void createStaticBody(Vector2 position, Shape shape, String name) {
BodyDef bodyDef = new BodyDef();
bodyDef.type = BodyDef.BodyType.StaticBody;
bodyDef.position.set(position);
FixtureDef fixtureDef = new FixtureDef();
fixtureDef.shape = shape;
Body body = world.createBody(bodyDef);
Fixture fixture = body.createFixture(fixtureDef);
if(name != null) fixture.setUserData(name);
}
The objects are added correctly, and are rendered correctly by the Box2DDebugRenderer.
The problem I have occurs when I want to handle myself overlaping of two objects. Using the ContactListener I find what Fixtures overlap (btw, all my game objects are made only by exactly one fixture), and then I do some magic.
The problem is: when I get the vertices from a fixture, all the data I get is the same, altough I request another vertex:
List<Vector2> subjectPolygon = new ArrayList<Vector2>();
for (int i = 0; i < polyA.getVertexCount(); i++) {
Vector2 vertex = new Vector2();
polyA.getVertex(i, vertex);
subjectPolygon.add(fA.getBody().getWorldPoint(vertex));
}
System.out.print("subject: ");
for(Vector2 vector2 : subjectPolygon) {
System.out.print(vector2 + ", ");
}
prints
subject: [16.055883:5.8014317], [16.055883:5.8014317], [16.055883:5.8014317], [16.055883:5.8014317]
Can anyone tell me if this is already a known bug, or I am doing something wrong?