Search code examples
javalibgdxscene2d

Ligdx Unable to position images in Stack


According to the wiki to have overlapping widgets the Stack should be used.

However, I could not find how to position the widgets inside the stack relative to each other. What I'm trying to achieve is to have a panel, where the players position is shown on top of a mini-map of the scene.

How can the actors inside the Stack positioned? Is there some other way to achieve this?


Solution

  • After looking around in the sourcecde a bit, it became clear why Stack didn't let any modification to size and position: it overwrites it.

    So since Stack Extends WidgetGroup I tried to use it, instead of Stack and the positioning actually works.

    minimap_border = new Image(used_skin.getRegion("panel"));
    minimap_border.setFillParent(false);
    minimap_border.setFillParent(true);
    minimap = new Image();
    minimap.setSize(120,120);
    minimap.setPosition(4,4);
    WidgetGroup minimapStack = new WidgetGroup();
    minimapStack.addActor(minimap_border);
    minimapStack.addActor(minimap);