Home Game Development java – Libgdx Scene2D Table background not displaying up

java – Libgdx Scene2D Table background not displaying up

0
java – Libgdx Scene2D Table background not displaying up

[ad_1]

I’m utilizing Libgdx’s Scene2D API to construct my UI and every little thing has been working as anticipated till now. I created a Skin and a TextureAtlas and linked them as so:

Skin pores and skin = new Skin();
TextureAtlas uiElements1 = new TextureAtlas("skins/uielements1.txt");
pores and skin.addRegions(uiElements1);
pores and skin.load(Gdx.information.inside("skins/uiskin.json"));

And then I attempted to create a Table:

Table desk = new Table(pores and skin);
desk.setWidth(stage.getWidth());
desk.align(Align.heart|Align.prime);
desk.setPosition(0, Gdx.graphics.getHeight());
desk.padTop(30);
desk.setBackground("grey_button02");

Finally, I added a Label to the Table:

Label recreationTitle = new Label("Nameless Project", pores and skin, "title");
desk.add(recreationTitle).padBottom(10).row();

Once I added the Table to my Stage, solely the weather in it could present up and never the background picture. I attempted utilizing background(String s), setBackground(String s), background(Drawable d), and setBackground(Drawable d). None of these appeared to work for me.

I additionally tried calling pack() and setFillParent(true) however each of these made my desk disappear. I’ve gone via nearly each Google outcome and I can not discover anybody else with my concern.

Here is my uiskin.json file

{
  com.badlogic.gdx.graphics.g2d.BitmapFont: { default-font: { file: fonts/FutureThin.fnt } },
  com.badlogic.gdx.scenes.scene2d.ui.Textual contentButton$Textual contentButtonType: {
   default: { down: blue_button03, up: blue_button04, font: default-font },
  },
  com.badlogic.gdx.scenes.scene2d.ui.Window$WindowType: {
    default:  {
      titleFont: default-font
     }
   },
   com.badlogic.gdx.scenes.scene2d.ui.Label$LabelType: {
    title: {
        font: default-font
     }
   }
}

And all the class rendering the stage:

public class MainMenu implements Screen {

    GameClass myGame;

    Stage stage;
    Skin pores and skin;

    Table desk;
    Textual contentButton singlePlayer;
    Textual contentButton multiPlayer;
    Label recreationTitle;


    public MainMenu(GameClass g) {
        myGame = g;

        // Create Skin, load texture Atlas, load pores and skin
        pores and skin = new Skin();
        TextureAtlas uiElements1 = new TextureAtlas("skins/uielements1.txt");
        pores and skin.addRegions(uiElements1);
        pores and skin.load(Gdx.information.inside("skins/uiskin.json"));

        // Create stage
        stage = new Stage(new ScreenViewport());

        // Create Table
        desk = new Table(pores and skin);
        desk.setWidth(stage.getWidth());
        desk.align(Align.heart|Align.prime);
        desk.setPosition(0, Gdx.graphics.getHeight());
        desk.padTop(30);
        desk.setBackground("grey_button02");

        // Game Title
        recreationTitle = new Label("Nameless Project", pores and skin, "title");
        desk.add(recreationTitle).padBottom(30).row();

        // Single Player button
        singlePlayer = new Textual contentButton("Single Player", pores and skin, "default");
        singlePlayer.addListener(new ClickListener() {
            @Override
            public void clicked(InputEvent e, float x, float y) {
                myGame.setScreen(new WorldTesting(myGame));
            }
        });
        desk.add(singlePlayer).width(300).padBottom(30).row();

        // Multiplayer Button
        multiPlayer = new Textual contentButton("Multiplayer", pores and skin, "default");
        multiPlayer.setWidth(350);
        multiPlayer.addListener(new ClickListener() {
            @Override
            public void clicked(InputEvent e, float x, float y) {
                // Change Scenes
            }
        });
        desk.add(multiPlayer).width(300).padBottom(30).row();

        stage.addActor(desk);
        Gdx.enter.setInputProcessor(stage);
    }

    public void present() {

    }

    public void render(float delta) {
        Gdx.gl.glClearColor(0, 0, 0, 1);
        Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);

        stage.act(Gdx.graphics.getDeltaTime());
        stage.draw();
    }

    public void conceal(){

    }
    public void resize(int x, int y) {

    }
    public void pause() {

    }
    public void resume() {

    }
    public void dispose() {

    }

}

[ad_2]

LEAVE A REPLY

Please enter your comment!
Please enter your name here