Frage

I am using Slick2D to code a little game, and after a lot of time that already went into it, I changed my mind and decided that I indeed want the game to be resizable. So I tried to use the app.setResizable() command, as suggested on the Slick2D wiki (and here: How to make slick2d resizable). But my eclipse just didnt find that method, so I looked it up on the Internet again, and noticed that all attributes and methods reliative to resizing are missing (such as wasResized(), isResized(), setResizable(), etc..). I have the latest version of Slick2D and eclipse, and probably the answer is pretty obvious, but I have been looking for hours and just cant find it.

Thanks for your help.

War es hilfreich?

Lösung

In your StateBasedGame, in your main method, you can call lwjgl's Display object,

 Display.setResizable(true);

This will allow you to resize/maximize the Display window. Make sure you have a recent version of lwjgl!

If you would like to resize the window and make sure the graphics object refreshes it size, you should call this in your update method:

    if(Display.getWidth() != container.getWidth() || Display.getHeight() != container.getHeight()) {
        try {
            app.setDisplayMode(Display.getWidth(), Display.getHeight(), false);
            app.reinit();
        } catch(Exception e) {
            e.printStackTrace();
        }
    }

And app is your AppGameContainer class. If you are doing gamestates, you can send a reference to the state when it is initialized. If not, you can make a global reference to your container so you can use this snippet of code anywhere in the class.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top