Texture libGDX 2nd Relief

I work in a truck with libgdx and box2d. In my game, 1 meter = 100 pixels. My 2nd relief is generated by me and created by points.

enter image description here

What I did was make a polygon area for the whole polygon and use texturewrap.repeat. The problem is that the size of my game is reduced 100 times to fit the box2d units.

So my camera width is 800/100 and height is 480/100. (8x4.8 pixels)

How I created a polygon area

box = new Texture(Gdx.files.internal("box.png"));
    box.setFilter(TextureFilter.Linear, TextureFilter.Linear);
    box.setWrap(TextureWrap.Repeat, TextureWrap.Repeat);

    TextureRegion region = new TextureRegion(box);

    psb = new PolygonSpriteBatch();

    float[] vertices = new float[paul.size];
    for (int i = 0; i < paul.size; i++) {
        vertices[i] = paul.get(i);
        if (i % 2 == 1)
            vertices[i] += 1f;

    }

    EarClippingTriangulator a = new EarClippingTriangulator();
    ShortArray sar = a.computeTriangles(vertices);
    short[] shortarray = new short[sar.size];
    for (int i = 0; i < sar.size; i++)
        shortarray[i] = sar.get(i);
    PolygonRegion pr = new PolygonRegion(region, vertices, shortarray);

    System.out.println(vertices.length + " " + shortarray.length);

    ps = new PolygonSprite(pr);

Now I just draw a polygonsprite on my polygonsprite package. This will make the polygon texture many times, but the image will be 100 times larger and very stretched. The left example is the one I want to do, and the right one is the way my game looks.

enter image description here

+4
3

PR , , , : https://github.com/libgdx/libgdx/pull/3799

. RepeatablePolygonSprite.

+2

, ( ), TextureRegion , , 100.

, region.setU2(100) region.setV2(100). [0,1], , , . TextureWrap, .

, TextureRegion alredy 100 x y. PolygonSprite , , .

, ...:)

+1

You can create a new texture by code. Take your level and fill it with your texture, and then remove the top to the background. Take a look at pixelmap. Perhaps this will help you.

Edit:

TextureRegion is not repeated to fit the size at which you even use the texture, or you use TiledDrawable.

+1
source

Source: https://habr.com/ru/post/1539110/


All Articles