SHARE
TWEET
Untitled
a guest
Oct 6th, 2015
100
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
- //
- //Works perfectly fine
- //
- protected Body createBody(Polygon inputPolygon) {
- ...
- body.setUserData(inputPolygon.getVertices());
- ...
- }
- //Later in the render method
- sr.setProjectionMatrix(cameraMatrix); //ShapeRenderer sr = new ShapeRenderer();
- sr.begin(ShapeRenderer.ShapeType.Line);
- Array<Body> bodies = new Array<Body>();
- world.getBodies(bodies);
- sr.setColor(Color.BLACK);
- for (Body b : bodies) {
- sr.polygon((float[]) b.getUserData());
- }
- sr.end();
- //
- //Produces inconsistent and glitchy results at best
- //
- protected Body createBody(Polygon inputPolygon) {
- ...
- ShortArray indices = triangulator.computeTriangles(inputPolygon.getVertices());
- //The TextureRegion is 100x40 px and the inputPolygon represents a part of this texture (the vertices/coordinates are
- //in the same scale, so an inputPolygon with the vertices (0, 0 100, 0 100, 40, 0, 40) would represent the whole TextureRegion.
- PolygonSprite polygonSprite = new PolygonSprite(new PolygonRegion(terrainTexture, inputPolygon.getVertices(), indices.items));
- polygonSprite.setOrigin(0, 0);
- body.setUserData(polygonSprite);
- ...
- }
- //Later in the render method
- Array<Body> bodies = new Array<Body>();
- world.getBodies(bodies);
- for (Body b : bodies) {
- ((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
- }
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.

