0
votes

I am trying to create a stage where i am going to draw Textbuttons on.

I can launch the program fine without any errors. But there is no textbuttons that appear.

The issue might be that i cannot set the size of the stage i am using.

Here is the code for the initializing:

@Override public void resize(int width, int height) { if(stage == null) stage = new Stage();

        stage.clear();

        Gdx.input.setInputProcessor(stage);

        TextButtonStyle style = new TextButtonStyle();

        style.up = skin.getDrawable("Button");

        style.down = skin.getDrawable("Button");

        style.font = buttonFont;

        startGameBtn = new TextButton("Start Game", style);

        startGameBtn.setWidth(300);

        startGameBtn.setHeight(150);

        startGameBtn.setX(Gdx.graphics.getWidth() / 2 - startGameBtn.getWidth() / 2);

        startGameBtn.setY((float) (Gdx.graphics.getHeight() / 1.5));

        startGameBtn.addListener(new InputListener() 
        {

        });

        stage.addActor(startGameBtn);

    }

And here is where i draw the button:

public void render(float delta) 
{
    Gdx.gl20.glClearColor(0, 0, 0, 1);

    Gdx.gl20.glClear(GL20.GL_COLOR_BUFFER_BIT);

    stage.act(delta);

    sb.begin();


    stage.draw();


    sb.end();
}

Thank you for any help! :)

1
resize? don't you mean create? ( I haven't used libgdx in a while and i'm in no condition to test right now )João Costa
Nah, i meant resize, so it will scale whenever you resize the window.Adam Brodin
yeah just noticed resize is also called in the life cycle at start :)João Costa
Yup. But do you know how to fix this issue tho? Doesen't draw anything..Adam Brodin
Oh my god. I feel so stupid. It was actually drawing the whole time, i just had a black button and a black background. RIPAdam Brodin

1 Answers

1
votes

Solved problem!

I accidently had a black background and a black button so it was actually drawing it, i just couldn't see it.

Cheers!