I want to create a game menu screen in LibGDX using scene2d package with following layout
| label |
| btn btn btn |
| label |
My code looks as follows:
Table table = getTable();
table.add(label1);
table.row();
table.add(button1);
table.add(button2);
table.add(button3);
table.row();
table.add(label2);
table.row();
But instead of what I want I get something like this:
| label |
| btn btn btn |
| label |
The reason is because each table.add()
method call creates a new one cell. But I want to place all my 3 buttons inside one cell. How can I achieve desired result, may be in LibGDX existing something like LinearLayout
or whatever else?
Call colspan(3)
on the cell that is returned to you when calling add(label);
ex.
Cell cell = table.add(label1);
cell.colspan(3);
This, as the name implies, sets how many columns the cell will span across.
You may need to set the alignment on the cell also by calling cell.center();
you can string together these calls since they all return the same cell object..
table.add(label1).colspan(3).center();
The Cell class doesn't seem documented for libgdx.. I simply went on the source code found here
The cell class documentation can be found here for now. It does seem to be missing from the official docs.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With