LibGDX and Scene2d - simple menu issue

I am using LibGDX and Scene2D to create a simple menu for my game.

Here is a simple example that works for me:

    table.add(gameLogo).row();
    table.add(button1).row();
    table.add(button2).row();
    table.add(button3).row();

I didn’t include the irrelevant code(including the table into the stage for example).

If I don’t include .row() to each object that I add to the table, then the menu isn’t aligning to the center, which is very odd, for example:

    table.add(gameLogo).row();
    table.add(button1);
    table.add(button2).row();
    table.add(button3);

Why is the menu behaving like that? should I use more Tables or add some HorizontalGroups perhaps?

If you need any additional information, or images I can provide, although it does the same for even the simplest menu implemention possible with LibGDX and Scene2d.

I’m not sure what the weird behavior is you are experiencing, as the table does what you told it to. Your first example would create a table with 1 column and 4 rows, the second example will produce a table with 2 columns and 2 rows.

If you want to understand how the table functions it’s best to check out the docs of the github project: https://github.com/EsotericSoftware/tablelayout

If you understand what is explained on that page you should be ready to go to make some layouts. One last note. Don’t try to make your tables too complicated. You can nest them (put a table in the cell of another table) and achieve more complex layouts with this. Just make a draft of your screen on paper and try to find out how you could structure the screen with the help of tables.

It’s a table, so it’ll align to rows and columns. If you want it centered, try colspan() to make a cell extend horizontally.

I will try it now, sounds like the answer!
Yeah I just figured out it’s a table :0
I guess that’s what happening when you binge a programming session on your game haha :slight_smile: