-1

Am trying to understand the following piece of code. According to the author, he is trying to reset the camera position based on the gutter width and height. By gutter, I take it the author means the black bars on the screen. The problem is that I cant seem to find the methods setViewport(int,int,boolean) and getGutterWidth() and getGutterHeight() on the Stage class. I think this code was written with an outdated Libgdx API. What am looking for is the equivalent code that will perform the same task as this outdated code:

private Stage stage;

public void resize(int width, int height){
stage.setViewport(MyGame.WIDTH, MyGame.HEIGHT, true);
stage.getCamera().translate(-stage.getGutterWidth(),
-stage.getGutterHeight(), 0);}  
Jos
  • 468
  • 1
  • 7
  • 20
i_o
  • 777
  • 9
  • 25

1 Answers1

1

These black bars are now handled by the viewport classes, see https://github.com/libgdx/libgdx/wiki/Viewports for a overview and short description.

In our case I would suggest a FitViewport:

Viewport viewport = FitViewport(MyGame.WIDTH, MyGame.HEIGHT, camera);
Stage stage = new Stage(viewport);
Pinkie Swirl
  • 2,375
  • 1
  • 20
  • 25
  • @i_o LibGDX is open-source - so you could also see the `Viewport.java` (or any other LibGDX) source file [on github](https://github.com/libgdx/libgdx/blob/master/gdx/src/com/badlogic/gdx/utils/viewport/Viewport.java) as well. – DoubleDouble Oct 15 '15 at 21:32