0
\$\begingroup\$

I have:

shapeRenderer.setProjectionMatrix(stage.getViewport().getCamera().combined);

And I tried to do the following in render():

shapeRenderer.rect(0, 0, stage.getViewport().getScreenWidth(), stage.getViewport.getScreenHeight());

Which full-screens the ShapeRenderer when I first run my project, but as soon as I resize the window, the rectangle starts to change size and go off-screen. I'm using a FitViewport on my Stage, is there any way to make the ShapeRenderer always be full screen?

\$\endgroup\$

1 Answer 1

0
\$\begingroup\$

You should use the methods getWorldWidth and getWorldHeight instead of the screen counterparts. "World" is the emulated size of the viewport while "screen" is your actual screen size.

\$\endgroup\$
2
  • \$\begingroup\$ Lucky call? You should actually give it the matrix you want to draw to. So if you have a camera for viewing the map and want to use shapeRenderer.setProjectionMatric(worldCamera.combined). If you want to use it on your fixed screen gui that's using the stage then getting the camera from the stage is perfectly fine. Just make sure you use resize() properly. \$\endgroup\$
    – Madmenyo
    Commented Feb 14, 2018 at 15:21
  • \$\begingroup\$ @Madmenyo They are setting the projection matrix (read: shapeRenderer.setProjectionMatrix(stage.getViewport().getCamera().combined);). And that is exactly why it's the wrong size. They cannot use the size of the screen since that is not in sync with the size of the viewport unless the viewport is a ScreenViewport. \$\endgroup\$
    – Charanor
    Commented Feb 14, 2018 at 15:49

You must log in to answer this question.

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