Hello. How can I make a button in libgdx ? Without any skins. There is a font (.png + .ftn). I make a Rectangle and want to put text into it. Font loaded in BitmapFont .
1 answer
Yes, with libgdx skins a complete ambush. Skins with Russian letters, I did not find. Drawing them by hand is very troublesome. Here are 3 options that I actually used:
Instead of a button, we take Image from scene 2D. You can fasten the clickListener to the Image. The text is also 2 options: either it is already in the picture, or output over the button via SpriteBatch, using BitmapFont.
We take all the same Button or TextButton (but do not specify the text). The advantage over Image is at least some click animation. For the necessary text we create glyphLayout. Because of this, we know the width and height of the text. We make the button a little higher and a little wider. And also display the text on the button via bitmapfont.draw.
In both cases, you still have to fasten the default English-language skin.
If you want no skins at all, it means no widgets at all. Then
- As a button, take the Texture. Well, or if you want a button with animation, then TextureRegion. Create a rectangle with dimensions similar to our texture. The Rectangle class has a contains method. This is for the click listener. Create a Vector3 touchPosition for click coordinates. Click to listen in the render body: if (Gdx.input.isTouched ()) {touchPosition.set (Gdx.input.getX (), Gdx.input.getY (), 0); if (rectangle.contains (touchPosition.x, touchPosition.y) {... here everything is that after clicking on the button}} The text is also output using bitmapfont.draw.