개발/게임

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

slayernoone 2016. 11. 5. 00:49

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