vertices[i] = Float.parseFloat(polygonStrings[i]); return new PolygonRegion(textureRegion, vertices, triangulator.computeTriangles(vertices).toArray());
public void draw (PolygonRegion region, float x, float y, float originX, float originY, float width, float height, float scaleX, float scaleY, float rotation) { float[] vertices = region.getVertices(); short[] triangles = region.getTriangles(); float[] textureCoords = region.getTextureCoords(); float sX = width / region.getRegion().getRegionWidth(); float sY = height / region.getRegion().getRegionHeight(); float fx1, fx2, fx3, px1, px2, px3; float fy1, fy2, fy3, py1, py2, py3;
vertices[i] = Float.parseFloat(polygonStrings[i]); return new PolygonRegion(textureRegion, vertices, triangulator.computeTriangles(vertices).toArray());
PolygonSprite poly; PolygonSpriteBatch polyBatch = new PolygonSpriteBatch(); // To assign at the beginning Texture textureSolid; // Creating the color filling (but textures would work the same way) Pixmap pix = new Pixmap(1, 1, Pixmap.Format.RGBA8888); pix.setColor(0xDEADBEFF); // DE is red, AD is green and BE is blue. pix.fill(); textureSolid = new Texture(pix); PolygonRegion polyReg = new PolygonRegion(new TextureRegion(textureSolid), new float[] { // Four vertices 0, 0, // Vertex 0 3--2 100, 0, // Vertex 1 | /| 100, 100, // Vertex 2 |/ | 0, 100 // Vertex 3 0--1 }, new short[] { 0, 1, 2, // Two triangles using vertex indices. 0, 2, 3 // Take care of the counter-clockwise direction. }); poly = new PolygonSprite(polyReg); poly.setOrigin(a, b); polyBatch = new PolygonSpriteBatch();
@Override public void create () { texture = new Texture(Gdx.files.internal("data/tree.png")); PolygonRegionLoader loader = new PolygonRegionLoader(); region = loader.load(new TextureRegion(texture), Gdx.files.internal("data/tree.psh")); // create a region from an arbitrary set of vertices (a triangle in this case) region2 = new PolygonRegion(new TextureRegion(texture), new float[] {0, 0, 100, 100, 0, 100}, new short[] {0, 1, 2}); camera = new OrthographicCamera(Gdx.graphics.getWidth(), Gdx.graphics.getHeight()); camera.position.x = 0; camera.position.y = 0; batch = new PolygonSpriteBatch(); debugRenderer = new PolygonRegionDebugRenderer(); Gdx.input.setInputProcessor(this); }
ctor() { textureSolid = makeTextureBox(1, 0xFFFF0000, 0, 0); float a = 100; float b = 100; PolygonRegion polyReg = new PolygonRegion(new TextureRegion(textureSolid), new float[] { a*0, b*0, a*0, b*2, a*3, b*2, a*3, b*0, a*2, b*0, a*2, b*1, a*1, b*1, a*1, b*0, }); poly = new PolygonSprite(polyReg); poly.setOrigin(a, b); polyBatch = new PolygonSpriteBatch(); }
vertices[i] = Float.parseFloat(polygonStrings[i]); return new PolygonRegion(textureRegion, vertices, triangulator.computeTriangles(vertices).toArray());
private void drawHoldBeam(Vector2 from, Vector2 to, float orgSize, float dstSize) { Vector2 delta = from.cpy().sub(to); float w = Math.max(orgSize, dstSize); float h = delta.len(); float tw = holdBG.getRegionWidth(); float th = holdBG.getRegionHeight(); float factorScale = (tw / w) * 0.5f; float topFactor = Math.max(dstSize - orgSize, 0f) * factorScale; float botFactor = Math.max(orgSize - dstSize, 0f) * factorScale; float[] points = { topFactor, 0f, botFactor, th, tw - botFactor, th, tw - topFactor, 0f }; PolygonRegion clamped = new PolygonRegion(holdBG, points, triangles); spriteBatch.draw(clamped, from.x - w * 0.5f, from.y, w * 0.5f, 0f, w, h, 1f, 1f, delta.angle() + 90); }