Fields and padding between elements in LibGDX

I have a VerticalGroup of Button on my screen. The problem is that the buttons are very close to each other. I want to add some spaces between the buttons, something like a pad or a field. I find the pad method in Table in the API, but VerticalGroup does not extend the table and therefore does not contain this method. Please tell me how I can add a space between buttons inside a VerticalGroup

Code example

 VerticalGroup buttons = new VerticalGroup(); buttons.addActor(btn1); buttons.addActor(bnt2); // ... and so on 
+6
source share
3 answers

Instead of adding a pad from the parent element ( VerticalGroup ), add a pad to each element ( Button s).

libGDX Button is also a Table and tables support various pad methods. They are documented to change the spacers around the outside of the table (or buttons in your case).

+3
source

Better late than never: libGDX uses TableLayout ( https://github.com/EsotericSoftware/tablelayout ) to order widgets. When you follow the link, and you go to the "Layout" section, you will see an image illustrating your situation. To get the margin (distance outside the button), you should use the following code:

  table.add(button).width(100).pad(10); table.row(); table.add(lastButton); 
+12
source

This is very, very new, but for those who read this question in the future, there is a space method in VerticalGroup that allows you to determine the distance between elements:

http://libgdx.badlogicgames.com/nightlies/docs/api/com/badlogic/gdx/scenes/scene2d/ui/VerticalGroup.html#space(float)

You can find an example of this in action, here:

https://github.com/libgdx/libgdx/blob/master/tests/gdx-tests/src/com/badlogic/gdx/tests/Scene2dTest.java

For those working with a slightly outdated version of libgdx, there is a setSpacing method that can be used instead.

+9
source

All Articles