Advertisement
madmenyo

LibGDX Polygon parser for Physics Body Editor output.

Oct 16th, 2015
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.92 KB | None | 0 0
  1.         String jsonText = loadJson();
  2.         JsonValue root = new JsonReader().parse(jsonText).getChild("rigidbodies");
  3.         float originX = root.get("origin").getFloat("x") * scale;// * texture.getWidth();
  4.         float originY = root.get("origin").getFloat("y") * scale;// * texture.getWidth();
  5.         origin = new Vector2(originX, originY);
  6.  
  7.         for (JsonValue polygon = root.getChild("polygons"); polygon != null; polygon = polygon.next())
  8.         {
  9.             float[] indices = new float[polygon.size * 2];
  10.  
  11.             int indiceCount = 0;
  12.             for (JsonValue vertex = polygon.child; vertex != null; vertex = vertex.next())
  13.             {
  14.                 indices[indiceCount] = vertex.getFloat("x") * (texture.getWidth() * scale);
  15.                 indices[indiceCount + 1] = vertex.getFloat("y") * (texture.getWidth() * scale);
  16.             }
  17.             polygons.add(new Polygon(indices));
  18.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement