Scene 2d - Camera resize Issue

Hey,

ive started to work on a main menue with libgdx and scene 2d.
my Main class (implements ApplicationListener) basicly creates a StageManager and lets him render and resize :

public void create() {
	Manager = new StageManager();
	}

@Override
	public void render() {
		if (((StageManager) this.Manager).getStage() != null) {
			Manager.render(Gdx.graphics.getDeltaTime());
		}
	}

	@Override
	public void resize(int width, int height) {
		if (Manager != null) {
			Manager.resize(width, height);
		}
	}

the Stage manager implements Screen.
The Constructor creates this first Stage :

public StageManager() {
		GameStage = new MainMenue(this);
		GameStage.getCamera().viewportWidth = Gdx.graphics.getWidth();
		GameStage.getCamera().viewportHeight = Gdx.graphics.getHeight();
		
	}

lets the stage render and rezise :

public void render(float delta) {
		Gdx.gl.glClearColor(0, 0, 0, 1);
		Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
		GameStage.act(Math.min(Gdx.graphics.getDeltaTime(), 1 / 30f));
		GameStage.draw();
	}
public void resize(int width, int height) {
		GameStage.getViewport().setWorldSize(width, height);
		GameStage.getCamera().viewportWidth = Gdx.graphics.getWidth();
		GameStage.getCamera().viewportHeight = Gdx.graphics.getHeight();
		System.out.println("Window got resized");
	}

in the MainMenue class (which extends Stage) i create a camera, set it to Ortho and set the SpriteBatch to it

camera = new OrthographicCamera();
		camera.viewportHeight = Gdx.graphics.getHeight();
		camera.viewportWidth = Gdx.graphics.getWidth();
		camera.setToOrtho(true);
		this.getSpriteBatch().setProjectionMatrix(camera.combined);

Now i have a Major problem, i create several Buttons and Text fields add Listeners to them and so on.
Most stuff works fine, but no matter how i change the camera stuff i always get problems if i resize the window.
I manage to let the Buttons keep there size or Scale with the window just as i like it, but the problem appears in both cases.
However if i resize there “Graphic” basicly does what i want, but there Input listeners or the Actor itself appears to stay at some other location.
Its like it always stays at the Same Point of the Stage Coordinate System and My Camera just moves or stretches the view, and with it the Graphics.

the result i get looks like this :

as long is i not resize it everything is nice and cool.
But as soon as i start to resize i have to click at “other” locations to get the buttons.
For example at the red X to get “Settings”.
the code for my buttons and table is like this :

[quote] table = new Table();
table.setFillParent(true);
table.setClip(true);
this.addActor(table);

button = new TextButton(text, skin);
button.setName(text);
table.add(button).minHeight(80).minWidth(250);
button.setPosition(x-button.getWidth()/2, y-button.getHeight()/2);
group.addActor(button);

button.addListener(new ChangeListener() {
public void changed (ChangeEvent event, Actor actor) {
buttonPressed(actor);

		}
	});

[/quote]
Why is this Happening and how can i fix this ?
thanks in advance.

EDIT
i forgot to mention, if i add this to the Stage Managers resize method:

[quote]GameStage.clear();
GameStage = new MainMenue(this);
[/quote]
everything works just fine, but i think thats a really really bad solution, so i hope someone can point out what i do wrong here :wink:

Some suggestions:

You should set the camera’s projection matrix at the start of each update. Otherwise changes in the camera wont be reflected in the rendering.

this.getSpriteBatch().setProjectionMatrix(camera.combined);

I’m not sure that changing the viewport wirdth and height directly works well as I’m not sure that this will update the projection matrix correctly:

      GameStage.getCamera().viewportWidth = Gdx.graphics.getWidth();
      GameStage.getCamera().viewportHeight = Gdx.graphics.getHeight();

There’s a method that actually updates the matrix:

GameStage.getCamera().setToOrtho(false, width, height);