Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to enable fullscreen when pressing a key in LibGDX

Tags:

libgdx

Hello kinda new to LibGDX and currently having issues with the fullscreen mode on pc, what i'm trying to do is set my game to fullscreen whenever someone presses a key and this doesn't do anything whenver i type something in the main method in desktopLauncher.java. And importing the LwjglApplicationConfiguration class in the core map doesn't work because it isn't available there for some reason.

like image 788
syclone Avatar asked Apr 06 '19 23:04

syclone


1 Answers

I tested the answer provided by PandaBR on this question and it works. https://gamedev.stackexchange.com/a/119867/81956

Put this in the render method of your main LibGDX / Game class (not DesktopLauncher). Change "Input.Keys.TAB" to be the key you want to toggle your program in and out of full screen mode.

if (Gdx.input.isKeyPressed(Input.Keys.TAB)){
    Boolean fullScreen = Gdx.graphics.isFullscreen();
        Graphics.DisplayMode currentMode = Gdx.graphics.getDisplayMode();
        if (fullScreen == true)
            Gdx.graphics.setWindowedMode(currentMode.width, currentMode.height);
        else
            Gdx.graphics.setFullscreenMode(currentMode);
}
like image 186
Tekkerue Avatar answered Oct 16 '22 21:10

Tekkerue