Search code examples
javalibgdx

How to create window without a title bar in libgdx


I have a project that needs to look like this:

enter image description here .

Using window I get the following result

enter image description here

I am creating the above result with the following code

private Table buildControlsWindowLayer() {
        Window window = new Window("", skinLibgdx);
        // + play button
        playButton = new Button(maputoSkin, "play");
        window.add(playButton).pad(10, 0, 10, 0).row();
        playButton.addListener(listener);
        // + options button
        optionsButton = new Button(maputoSkin, "options");
        window.add(optionsButton).pad(10, 0, 10, 0).row();
        optionsButton.addListener(listener);
        // + leaders button
        leadersButton = new Button(maputoSkin, "leaders");
        window.add(leadersButton).pad(10, 0, 10, 0).row();
        leadersButton.addListener(listener);
        if (Constants.DEBUG_FLAG_MENU_SCREEN) window.debug();
        window.pack();
        window.setPosition(Constants.VIEWPORT_GUI_WIDTH / 2 - window.getWidth()/2,
                           Constants.VIEWPORT_GUI_HEIGHT/2 - window.getHeight());
        return window;
    }

My questions

I. How can I get rid of the title bar

II. How can I set my own background instead of libgdx default

III. Is this approach correct for third kind of situation?


Solution

  • My approach was using the table instead of window and define its background as ninepatch drawable from the skin

        Skin skin = SkinManager.getInstance().getSkin();
        final Table outerTable = new Table();
        outerTable.setFillParent(true);
        stage.addActor(outerTable);
    
        // Layer to hold the buttons and dark background
        Table buttonsTable = new Table();
    
        playButton = new TextButton("Play", skin, "play");
        settingsButton = new TextButton("Setting", skin, "setting");
        highScoreButton = new TextButton("Leaders", skin, "leaders");
    
        buttonsTable.add(playButton).width().height().pad();
        buttonsTable.row();
        buttonsTable.add(settingsButton).width().height().pad(0);
        buttonsTable.row();
        buttonsTable.add(highScoreButton).width().height().pad();
        buttonsTable.row();
        // + background color
        buttonsTable.setBackground(controlsBackground);
    
        // Adding button table to outer table
        outerTable.add(buttonsTable).colspan(2).expand();
    

    I leave width() height() and pad() empty because they depend on the size of your world. And one thing

    controlsBackground = new NinePatchDrawable(new NinePatch(
                    SkinManager.getInstance().getSkin().getRegion("menu-background"), 10, 10, 10, 10
            ));