Adam Brodin
Adam Brodin

Reputation: 71

Libgdx stage issue

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! :)

Upvotes: 0

Views: 309

Answers (1)

Adam Brodin
Adam Brodin

Reputation: 71

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!

Upvotes: 1

Related Questions