Search code examples
javaresizewindowslick2d

How to make slick2d resizable


Hey guys I was wondering if there was a way to make slick2d resizable by the user.(I have researched this and only found out how to make the program resizable within the program)

Here is my code and thanks in advance.

package Main;
import States.Menu;
import States.Play;
import org.newdawn.slick.*;
import org.newdawn.slick.state.*;

/**
 *
 * @author Kyle
 */
public class Lawu extends StateBasedGame{

    public static final String gamename = "Lawu";
    public static final int menu = 0;
    public static final int play = 1;

    public static int height=600,width=760;

    public Lawu(String gamename)
    {
        super(gamename);
        this.addState(new Menu(menu));
        this.addState(new Play(play));
    }

    public static void main(String[] args) {
        AppGameContainer appgc;
        try{
            appgc = new AppGameContainer(new Lawu(gamename),width, height, false);
            appgc.start();
        }
        catch(SlickException e)
        {
            e.printStackTrace();
        }
    }

    public void initStatesList(GameContainer gc) throws SlickException {
        this.getState(menu).init(gc, this);
        this.getState(play).init(gc, this);
        gc.setIcon("res/Monster.png");
        this.enterState(menu);
    }
}

Solution

  • Put this before appgc.start():

    appgc.setResizable(true);