How to deal with different aspect ratios in libGDX?

后端 未结 7 2198
粉色の甜心
粉色の甜心 2020-11-29 16:16

I have implemented some screens using libGDX that would obviously use the Screen class provided by the libGDX framework. However, the implementation for these s

相关标签:
7条回答
  • 2020-11-29 17:01

    This code works for me with the latest update: * OrthographicCamera is cam, this makes no cropping, just changes the viewport so the width is still "that many" times larger than the actual window/device

    public void resize(int width, int height) {
        int newW = width, newH = height;
        if (cam.viewportWidth > width) {
            float scale = (float) cam.viewportWidth / (float) width;
            newW *= scale;
            newH *= scale;
        }
    
        // true here to flip the Y-axis
        cam.setToOrtho(true, newW, newH);
    }
    
    0 讨论(0)
提交回复
热议问题