I just fixed another issue regarding the scaling inside a ScreenViewport. And yet another problem arises:

If I'm understanding the wiki correctly, a ScreenViewport does not scale or stretch the content in any way. In my case it somehow does:

When the game is started, it looks like this:

enter image description here

And after resizing the window (e.g. making it wider) it looks like this (obviously stretched...):

enter image description here

(The code is mostly still the same as in the linked question).

Since I couldn't find a example of using a ScreenViewport with unitScale yet, I have no idea how to make this work... Thanks in advance :)


2 Answers 2


You should call viewport.update(width, height); inside resize method of screen.

public void resize(int width, int height) {
    viewport.update(width, height);

More info here https://github.com/libgdx/libgdx/wiki/Viewports

  • \$\begingroup\$ I did that, but the resize(width, height) call wasn't forwarded properly to the screen. That's solved now, but now the viewport is only displayed correctly when resizing (it's flickering between the right viewport scale and the stretched behavior...). \$\endgroup\$ Commented Sep 11, 2015 at 10:50
  • \$\begingroup\$ Ok, I figured out that it's caused by rendering the RayHandler... \$\endgroup\$ Commented Sep 11, 2015 at 11:03

So, to make it work I needed to call useCustomViewport(x, y, width, height) on the rayHandler inside of resize(width, height).

  • \$\begingroup\$ I downvoted this because Andrej posted the answer two hours before you answered your own. He could not have known you where calling your viewport useCustomViewport without seeing your code. Accept his and delete this one to get rep back. \$\endgroup\$
    – Madmenyo
    Commented Sep 11, 2015 at 15:18
  • \$\begingroup\$ @MennoGouw My code is linked in my question... see \$\endgroup\$ Commented Sep 11, 2015 at 15:47
  • \$\begingroup\$ @MennoGouw Also, the useCustomViewport was causing this strange display behavior, since I didn't call it in resize and my constructor. \$\endgroup\$ Commented Sep 12, 2015 at 9:23
  • \$\begingroup\$ I overlooked that. But still the answer of Andrej is proper. \$\endgroup\$
    – Madmenyo
    Commented Sep 12, 2015 at 9:25
  • \$\begingroup\$ @MennoGouw It's totally valid, but I did call viewport.update(width, height), so that wasn't the cause, which means that his suggestion wasn't the solution. \$\endgroup\$ Commented Sep 12, 2015 at 9:29

You must log in to answer this question.

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