Search code examples
javalibgdx

Stage is bigger than the screen in LibGDX, how to fit it in the screen?


I'm developing a game in libGDX, and the levels in my grid contains a grid actor which contains mirrors inside (see my game). The problem is that the grid is too big and I want to be able to see all the stage.

I'm using an OrthographicCamera and an ExtendViewport.

I tried using frustrum (I don't really know what it is): I create four BoundingBox (left, right, top and down) which are placed out of the grid. I set the camera position to the middle of the grid actor and i make a loop zooming the camera until the boxes are in the frustrum, but I don't know if it is the best solution...


Solution

  • I think you want to use a FitViewport, which will make sure you don't 'spill' off the screen.

    FYI, the frustum is used to determine depth of your camera- how far it can see. I agree that that won't help you in this situation.