Search code examples
androidlibgdxstage

Stage doesn't get drawn


I created a super class with nothing in the render method:

public class SuperClass implements InputProcessor {

    public SuperClass(MyGame game) {

    }

    public void render() {

    }

    // InputProcessor overriden methods here
}

In a subclass I override the render method:

public class SubClass extends SuperClass {

Stage stage;

public SubClass(MyGame game) {
    super(game);

    stage = new Stage(0, 0, false);

    skin = new Skin(Gdx.files.internal("data/uiskin.json"));

    Gdx.input.setInputProcessor(stage);

    Image image = new Image(new Texture(Gdx.files.internal("bg.png")));
    image.setPosition(0, 0);
    image.setWidth(800);
    image.setHeight(480);
    stage.addActor(image);

}

@Override
public void render() {

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

    stage.draw();

}

}

But the stage doesn't get drawn. I know this because I expect to see the background image but its just a blank screen.

What am I doing wrong here?


Solution

  • The line in the SubClass constructor should be:

    stage = new Stage(800, 480, false);
    

    or you can also do this:

    stage = new Stage()
    

    but then you have to set the viewport, stage.setViewport(float, float, boolean) in resize(float, float).