http://gamedev.stackexchange.com/questions/80503/is-table-the-only-layout-that-i-can-use-in-libgdx



Is Table the only layout that I can use in libgdx?

I'm looking for the common way to handle the layout in libgdx. I searched google and found only table layout. Meanwhile I don't use any layout and just insert coordination into each visual object but I think that this is not the proper way to do it...
Is their any other layout that I can use?

p.s The game layout should split into two parts, left is smaller that the right and contains things like score time and info about stuff in the game. The right part will display the game-play itself

enter image description here

shareimprove this question

Definitely not. Table is just a tool and you should use it when it fits your desired result. If your widgets are supposed to be laid out in a tabular way, then use Table. Otherwise, it's perfectly okay to position your widgets manually if that's what you need.

Two alternatives to Table

  • HorizontalGroup: Just one example of a component made specifically for helping with with your layout. It seems to be what you are looking for.

  • Two Stage instances: have one Stage for the game area and one for the interface. Each Stagewill have its own camera, which means you can move the game camera around the world while the interface camera stays still. To control how large each Stage is and where it is positioned, read about Viewports on the LibGDX wiki.

When positioning manually

One piece advice, though, if you decide to position your widgets manually: don't use absolute pixel coordinates. If you your screen is 400px wide and you want a widget's X coordinate to be 200px, set it to 0.5f * screenWidth, instead. This will allow your widgets to be position correctly, even if the screen size changes and it takes no extra effort on your part.


Edit: The HorizontalGroup should have two children: a InterfaceWidget and a GameWidget. The InterfaceWidget will have as children all the things you want to appear in the left of the screen, such as score. The GameWidget will be the parent of the PlayerActor and any other actors you have in your game.

HorizontalGroup
  InterfaceWidget
    ScoreWidget
    SomeOtherWidget
  GameWidget
    PlayerActor
    SomeOtherActor
shareimprove this answer
   
So if I understand you, I need to use two stages with horizontal group and the left stage will contain vertical group? p.s my world doesn't move. Its something like board game. – 11alex11 Jul 19 '14 at 8:56
   
@11alex11 Either choose HorizontalGroup or two Stage instances. But since your world doesn't move, the HorizontalGroup is a better solution because it's simpler. :) – Paul Manta Jul 19 '14 at 9:00 
   
I am new to libgdx and I think that I'm missing something. On the right side of the screen I have only actors that I add randomly (x,y) in some range. the left side is also actors (score,time atc'...) I don't see how I need to work with HorizontalGroup.. – 11alex11 Jul 19 '14 at 9:07 
   
@11alex11 See the edit I made to my answer. – Paul Manta Jul 19 '14 at 9:16


'개발 > 게임' 카테고리의 다른 글

Game menu always at bottom  (0) 2016.11.05
LibGDX 구조  (0) 2016.11.03
How can I map regions on a world map image?  (0) 2016.11.01

http://www.badlogicgames.com/forum/viewtopic.php?f=11&t=24084&p=98276&hilit=gui+menu#p98276




Game menu always at bottom

Postby Grzesiek » Wed Oct 26, 2016 7:56 pm

Hi,
I search at google how to create table as a sub menu with image buttons which will be always at screen bottom.
So far I created table with whole stuff I need, but table moves always when I move game world, but I need this table as a game menu at constant position at screen bottom.

Do you know any good solution or tutorial how to do this?

CODE: SELECT ALL
    protected void setupMenuTable() {
        menuTable = new Table();
        menuTable.setSize(AssetsManager.MENU_BUTTON_WIDTH, AssetsManager.MENU_BUTTON_HEIGHT * 5);
        menuTable.setFillParent(true);
        menuTable.align(Align.bottom);

        ImageButton endTurn = new ImageButton(getMenuButtonStyle(MainMenuButtons.NEW_GAME.name()));
        endTurn.addListener(new ChangeListener() {
            public void changed (ChangeEvent event, Actor actor) {
                game.setScreen( new GameScreenScreen(game));
                dispose();
            }
        });

        ImageButton mainMenu = new ImageButton(getMenuButtonStyle(MainMenuButtons.EXIT.name()));
        mainMenu.addListener(new ChangeListener() {
            public void changed (ChangeEvent event, Actor actor) {
                game.setScreen( new MainMenuScreen(game));
                dispose();
            }
        });

        menuTable.add(endTurn);
        menuTable.add(mainMenu).padLeft(10);
        stage.addActor(menuTable);
    }


CODE: SELECT ALL
    @Override
    public void render(float delta) {
        Gdx.gl.glClearColor(0.25f, 0.25f, 0.25f, 10f);
        Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);

        stage.act(Math.min(Gdx.graphics.getDeltaTime(), 1 / 30f));
        stage.draw();

        camera.update();
        renderer.setView(camera);
        renderer.render();
    }
Grzesiek
 
Posts: 8
Joined: Sun Oct 02, 2016 6:44 am

Re: Game menu always at bottom

Postby evilentity » Wed Oct 26, 2016 8:03 pm

You need to use another camera for gui only.
evilentity
 
Posts: 2947
Joined: Wed Aug 24, 2011 11:37 am

Re: Game menu always at bottom

Postby MMM1412 » Sun Oct 30, 2016 8:08 am

Or create a MenuStage , add your menu Into that, render MenuStage after game stage.


'개발 > 게임' 카테고리의 다른 글

Is Table the only layout that I can use in libgdx?  (0) 2016.11.05
LibGDX 구조  (0) 2016.11.03
How can I map regions on a world map image?  (0) 2016.11.01



1. Screen > Stage > Actor > Action 요렇게 구성되는거 같다.

'개발 > 게임' 카테고리의 다른 글

Is Table the only layout that I can use in libgdx?  (0) 2016.11.05
Game menu always at bottom  (0) 2016.11.05
How can I map regions on a world map image?  (0) 2016.11.01

http://gamedev.stackexchange.com/questions/92038/how-can-i-map-regions-on-a-world-map-image



You could use polygons, or you could do a quick and dirty hack and just get a political map like this one: this one. Then, pick a unique color for each country and flood fill it in paint or photoshop. Then, you have a simple file that just has the mapping of countries/provinces to particular colors. Just something like this:

# Country,      #Unique RGB color
"Afghanistan",     (0, 0, 0)
"Albania",         (1, 0, 0)
...
"United Kingdom",  (255, 0, 0)
"United States",   (0, 1, 0)
...
"Kingdom of Zzyx", (0, 255, 0)
"ZZZland",         (0, 0, 1)
...

Then, when the player clicks on the map, just sample the color image, and find the color associated with it. Of course, this will be limited to the resolution of the selection image. This also gives you control over the political boundaries you want to select. For instance, if you just want to select continents, you could use an image like this: image

'개발 > 게임' 카테고리의 다른 글

Is Table the only layout that I can use in libgdx?  (0) 2016.11.05
Game menu always at bottom  (0) 2016.11.05
LibGDX 구조  (0) 2016.11.03

+ Recent posts