SHARE
TWEET

Untitled

a guest Oct 6th, 2015 100 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //
  2. //Works perfectly fine
  3. //
  4. protected Body createBody(Polygon inputPolygon) {
  5.         ...
  6.         body.setUserData(inputPolygon.getVertices());
  7.         ...
  8. }
  9. //Later in the render method
  10.         sr.setProjectionMatrix(cameraMatrix); //ShapeRenderer sr = new ShapeRenderer();
  11.         sr.begin(ShapeRenderer.ShapeType.Line);
  12.         Array<Body> bodies = new Array<Body>();
  13.         world.getBodies(bodies);
  14.         sr.setColor(Color.BLACK);
  15.         for (Body b : bodies) {
  16.         sr.polygon((float[]) b.getUserData());
  17.         }
  18.         sr.end();
  19.  
  20. //
  21. //Produces inconsistent and glitchy results at best
  22. //
  23. protected Body createBody(Polygon inputPolygon) {
  24.         ...
  25.         ShortArray indices = triangulator.computeTriangles(inputPolygon.getVertices());
  26.         //The TextureRegion is 100x40 px and the inputPolygon represents a part of this texture (the vertices/coordinates are
  27.         //in the same scale, so an inputPolygon with the vertices (0, 0  100, 0  100, 40,  0, 40) would represent the whole TextureRegion.
  28.         PolygonSprite polygonSprite = new PolygonSprite(new PolygonRegion(terrainTexture, inputPolygon.getVertices(), indices.items));
  29.         polygonSprite.setOrigin(0, 0);
  30.         body.setUserData(polygonSprite);
  31.         ...
  32. }
  33. //Later in the render method
  34.         Array<Body> bodies = new Array<Body>();
  35.         world.getBodies(bodies);
  36.         for (Body b : bodies) {
  37.             ((PolygonSprite) b.getUserData()).draw(batch); //Yes the screen is cleared correctly before, the batch is a PolygonSpriteBatch, the batch is started with begin() and end() and the projection matrix is set correctly
  38.         }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top