I have been making a project in libGDX and started in v0.9.9, I just got a mac in order to get it on ios, and after a series of figuring out the new libGDX and robovm updates and weighing options (through a variety of trial and error) i am going to have to update everything to the new libgdx 1.2.0 structure (gradle, etc.). This came with the addition of viewports and messed up the way stages work. Orginally in my constructor I would start by creating an orthograhiccamera and stage, ie:
camera = new OrthographicCamera(854, 480);
stage = new Stage();
I cant figure out how to factor the camera into the new code because I know somewhere i need to create a viewport for the stage but im not sure how my camera needs to work with it. All that shows up is just a white screen. Now after repeatedly fiddling with how i have a random made viewport, camera and stage setup, I actually got it to show the main menu buttons, but over blank white when there should be 3 moving backgrounds (it makes a cool paralax effect...) and moving title along with it. Could this be how libGDX now uses openGL 2.0 instead of 1.0? These button actors are also completely unresponsive, they should be animated when clicked, and change screen, and output to the console but do not do anything. I have always had the stage as the inputprocessor set in the show method, and add all of my actors aswell, ie:
@Override
public void show() {
Gdx.input.setInputProcessor(stage);
stage.addActor(variousActors);
}
Could the whiteness be opengl not being able to process the images and showing white instead? Could this be because of lack of ram (never a problem before whether on 20mb of available ram or 8gb available), could it be that the images being used are too large (largest being 3840 x 1080)? In my render is:
public void render(float delta) {
Gdx.gl.glClearColor(1F, 1F, 1F, 1F);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
batch.setProjectionMatrix(camera.combined);
camera.update();
stage.act(delta);
batch.begin();
batch.end();
stage.draw();
System.out.println("menuscreen rendering");
}
--All actors/elements are initialized in the constructor
My entire game is actually built out of scene-2d elements --it did actually work out really well:) -- so getting this to work means the whole game. Ive been looking around alot and have found no solutions. So in review, How do i properly use a viewport with stages and how do i setup my camera with it; Why are my stage/actors(buttons) unresponsive; Why does everything show up as complete whiteness other than my buttons?
Try creating the stage this way:
camera = new OrthographicCamera(854, 480);
viewport = new ScalingViewport(Scaling.stretch, Gdx.graphics.getWidth(), Gdx.graphics.getHeight(), camera);
viewport.update(Gdx.graphics.getWidth(), Gdx.graphics.getHeight(), true);
stage = new Stage(viewport, batch);
You don't have to use a ScalingViewport. Check https://github.com/libgdx/libgdx/wiki/Viewports for other possibilities.
In resize(int, int)
, as already mentioned, try:
viewport.update(width, height, true);