Slick2D Methods are missing

寵の児 提交于 2019-12-11 16:09:12

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/22153057/slick2d-methods-are-missing

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!