Libgdx changing window size without disabling resize on desktop

I’ve been trying to resize the window in my game by reading their preferred window size. Now, when it has been set, the user isn’t able to resize the game any more. I used this code to resize the window:

//userWidth and userHeight are both intergers already initialized.
DisplayMode desktopDisplayMode = Gdx.graphics
                    .getDesktopDisplayMode();
            Gdx.graphics.setDisplayMode(userWidth,
                    userHeight, true);

I’ve tried to put code for window resizing in the DesktopLauncher.java file, but then I can’t use the Gdx.app.getPreferences(), because it throws an error.

LwjglApplicationConfiguration config = new LwjglApplicationConfiguration();
config.height = userHeight;
config.width = userWidth;

Is there any other way to resize the window, or is there a way to make the window resizeable again?

Answer

This is a bug in LibGDX: https://github.com/libgdx/libgdx/issues/2635

As you can see, it’s fixed in v.1.5.1 so just update libGDX in your project. In case you’re using Gradle it’s pretty simple to do, just update gdxVersion in build.gradle file:

allprojects {
    ...    
    ext {
        ...
        gdxVersion = '1.5.1'
    }
}

Leave a Reply

Your email address will not be published. Required fields are marked *