I have my own Libgdx class that does not implement the Screen Interface. I control my camera movement. It's an orthographic camera whose viewport width is WorldWidth and viewport height is WorldHeight. I am trying to add a button via the Stage class. I am able to add it and I see that its drawn, but since I don't implement the screen interface I call stage.draw() on my render() method, not on the render(float delta) method that seems to be required by the Screen interface. For comparison purposes, I draw a sprite whose size is (0.25fcamera.viewportWidth,0.25fcamera.viewportHeight). However, this sprite is not drawing when I call stage.draw(). The button draws but it seems very small even though I set its size to (0.25fcamera.viewportWidth,0.25fcamera.viewportHeight). Here's the code on how I add my button class:
stage1= new Stage();
btn = new Button(new SpriteDrawable(new Sprite(new Texture("texone.png"))),
new SpriteDrawable(new Sprite(new Texture("textwo.png"))));
btn.addListener(new ClickListener(){
public void clicked(InputEvent event, float x, float y){ }
});
btn.setBounds(0f,0f,0.25f*camera.viewportWidth,0.25f*camera.viewportHeight);
btn.setPosition(0f,100f);
stage1.add(btn);
Gdx.input.setInputProcessor(stage1);
//a few lines down to my render() method
@Override
public void render(){
//.... more regular code that goes in method
batch.begin();
//more lines of code that draw my sprites
stage1.draw();
batch.end();
}
What I want to know is why is the button so small and why isn't my other sprite drawing? Perhaps there is a way to add my orthographic camera to my stage1 object. And, if I add my orthographic camera to my stage1 object, how should I update my stage1 viewport on the resize method? Please advise.
thank you