private Shape getPolyline(PolylineMapObject polylineObject) { float[] vertices = polylineObject.getPolyline().getTransformedVertices(); Vector2[] worldVertices = new Vector2[vertices.length / 2]; for (int i = 0; i < vertices.length / 2; ++i) { worldVertices[i] = new Vector2(); worldVertices[i].x = vertices[i * 2] / units; worldVertices[i].y = vertices[i * 2 + 1] / units; } ChainShape chain = new ChainShape(); chain.createChain(worldVertices); return chain; } }
public Body createRectBody(float x, float y, float width, float height) { x = x/scale; y = y/scale; width = width/scale; height = height/scale; BodyDef def = new BodyDef(); def.type = BodyDef.BodyType.StaticBody; def.position.set(x, y); Body body = world.createBody(def); ChainShape shape = new ChainShape(); float[] vertices = { 0, 0, 0, height, width, height, width, 0, 0, 0 }; shape.createChain(vertices); body.createFixture(shape, 1); shape.dispose(); return body; }