Search code examples
javalibgdx

Add a background to a Vertical Group


How can one go about adding a background to a LibGDX Vertical Group?

I've checked the documentation for the class and it seems like there isn't a clean way to do so.


Solution

  • You can add an Image actor to a Group, then add the Vertical Group to said Group. If you set the Group's dimensions to that of the Image actor, then set the Vertical Group to fill its parent, then you have effectively added a background to a Vertical Group.

    Example:

    Group g = new Group();
    
    Image i = new Image(new Texture("pathtosomeimage.png"));
    
    VerticalGroup vg = new VerticalGroup();
    
    g.setSize(i.getWidth(), i.getHeight());
    vg.setFillParent(true);
    
    g.addActor(i);
    g.addActor(vg);
    
    //add stuff to the Vertical Group