Suppose I have a Level 1 tilemap which is 32 x 16 tiles in size, and when the player exits into another room, which is on 10 x 6 tiles in size, what's the best way to center the viewport. At the moment I am positioning my game cam as follows:
gameCam = new OrthographicCamera();
gameCam.setToOrtho(false,320,240);
gamePort = new FitViewport(Darkcaster.V_WIDTH / Darkcaster.PPM, Darkcaster.V_HEIGHT / Darkcaster.PPM, gameCam);
gameCam.position.set(gamePort.getWorldWidth() / 2, gamePort.getWorldHeight() / 2, 0);
The 320x240 is the screen resolution I wanted, and V_WIDTH/V_HEIGHT was also set to 320/240, as this was the size of my first level.
What I want is the smaller level to be centered in the screen (like a mini bonus room) and then I can fill the rest with black, but the scale of the tiles etc needs to stay the same.
I can get the map properties to work out how wide and tall each map is, but can't work out the math I need to get it working.
Obviously on levels which are bigger than the viewport (scrolling levels) the camera would just be centered on the player, but the smaller level would be in the center of the screen and not scroll.
Any ideas on the best way to achieve this?
Thanks
J