LibGDX - Rounded shaped texture

879 views Asked by At

I was wondering if it possible to give a shape to a Texture in LibGDX.

In particular, I have a Texture and I want to make a button out of it. To do so, I wanted to give it a rounded corners shape.

In a nutshell, I have this :

enter image description here

and I want this :

enter image description here

I've already read some similar questions with any clear answer. Does anyone have experience this problem and found a smart solution ?

2

There are 2 answers

0
arv On BEST ANSWER

Create rounded texture image using bellow method and then add text to it.

public static Texture createPixmapRoundCornerRect(Color color, int width,
            int height, int radius) {
        Pixmap pixmap = new Pixmap(width, height, Format.RGBA8888);
        pixmap.setColor(color);
        pixmap.fillCircle(radius, radius, radius);
        pixmap.fillCircle(width - radius, radius, radius);
        pixmap.fillCircle(width - radius, height - radius, radius);
        pixmap.fillCircle(radius, height - radius, radius);
        pixmap.fillRectangle(0, radius, width, height - (radius * 2));

        pixmap.fillRectangle(radius, 0, width - (radius * 2), height);
        Texture pixmaptex = new Texture(pixmap);
        pixmap.dispose();
        return pixmaptex;
    }
0
bitbrain On

This has been already answered here. You have to implement your own Texture which uses polygons to achieve what you are trying to do.