Search code examples
androidlibgdx

Graphic problems with libgdx stage2d.ui


I'm playing with stage2d.ui... Just creating an empty stage with only a button, and it happens this in android (screenshot directly from a Nexus5): Screenshot from a Nexus5

Also, it looks ok in desktop, but if you resize the screen, you can see the image of the button flickering at its previous position like this (image after making the window a bit more width): Desktop behaviour

I'm not sure if I'm doing something wrong or it's just a graphic issue...

For the button widget, I'm using the test data like this:

stage = new Stage(new ScreenViewport());
Skin skin = new Skin(Gdx.files.internal("uiskin.json"));

TextButton button = new TextButton("Button 1", skin);
button.setSize(100, 50);
button.setPosition(10, 10);

stage.addActor(button);

And then in the main render method, stage.act(delta) and stage.draw() are called, of course.

For the resize part... here's the code

public void resize(int width, int height) {
    stage.getViewport().update(width, height);
}

I have other stages without ui widgets working fine, but this is my first time with ui and I'm not sure about what's happening here...


Solution

  • Moved from comment above.

    My guess is you are not clearing the screen at the start of your render method. Try adding Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); if it isn't there already.