1
\$\begingroup\$

I have two cameras initialized as such:

val mainCamera: OrthographicCamera by lazy { OrthographicCamera(WIDTH * ZOOM, HEIGHT * ZOOM) }
val guiCamera: OrthographicCamera by lazy { OrthographicCamera(WIDTH, HEIGHT) }

override fun initialize() {
    mainCamera.setToOrtho(false, WIDTH * ZOOM, HEIGHT * ZOOM)
    mainCamera.update()

    guiCamera.setToOrtho(false, WIDTH, HEIGHT)
    guiCamera.update()
}

Where WIDTH and HEIGHT values are 960f and 640f respectively and zoom is 0.5f for mainCamera.

mainCamera is used for showing everything game related (following the player mainly) and doesn't use Scene2D, while guiCamera is used for displaying the GUI and is exclusively used within a Scene2D stage and is set in stages constructor like this:

private val stage: Stage by lazy { Stage(StretchViewport(WIDTH, HEIGHT, cameraSystem.guiCamera), batch) }

However when I change the viewport of the stage to FitViewport it seems that everything is shrunk and letterboxed, even the mainCamera.

shrinkage

I expected that using FitViewport with a specific camera would only perform scaling on entities using that camera, not on the whole scene.

Is this how it should work or am I doing something wrong? Sprite and map rendering systems render to the mainCamera and all rendering systems use the same batch, however I've also tried instantiating the stage with it's own dedicated batch so it had both it's own camera and a batch and still everything was shrunk.

P.S: The language used is Kotlin so the syntax is a little different from Java however most of the concepts are the same and straightforward. I'd only like to explain the by lazy syntax to those not familiar with Kotlin. by lazy means that the property won't be initialized until it's accessed for the first time. It allows me to define a final/constant (val) property but delay it's initialization until libgdx context is properly initialized and until artemis-odb system dependencies are injected.

\$\endgroup\$

1 Answer 1

-1
\$\begingroup\$

I just figured this out. You need 2 viewports and need the cameras assigned to those viewports. Then before you render you need to call apply() on those viewports so glViewport is set and used.

More info at the official docs: https://github.com/libgdx/libgdx/wiki/Viewports#multiple-viewports

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .