Search code examples
libgdxscene2d

Is there a way to layout a scene2d.ui Stack?


I'm trying to make a hotkey type button which has a main image, a number in the top left indicating the hotkey button, and a number in the bottom right indicating the quantity of the item. I could use a Table to place these but they wouldn't be overlapping. I'd like to have the numbers on top of the main image so I used a stack, unfortunately it doesn't look like there's a way to control the actors on a stack - they all get placed at 0,0 within the biggest actor in the stack. Is there a way to place the actors in the appropriate positions or do I have to use table?


Solution

  • By definition, Stack puts its children in 0,0 coordinates and trying to stretch them to fill Stack.

    You can use Group, for more control over actors you putting in:

    You can simply get X and Y coordinates of inserted Actor by getX() and getY() methods. With little bit of help by getHeight() and getWidth() methods you can make simple table layout.