I am developing a tile-based strategy game using Java and the Slick API.

So far so good, but I've come to a standstill on my options menu. I have plans for the user to be able to change the resolution during gameplay (it is pretty common, after all).

I can already change to fullscreen and back to windowed, this was pretty simple...

//"fullScreenOption" is a checkbox-like button.
if (fullScreenOption.isMouseOver(mouseX, mouseY)) {
   if (input.isMouseButtonDown(Input.MOUSE_LEFT_BUTTON)) {
      fullScreenOption.state = !fullScreenOption.state;

But the container class, contrary to my previous beliefs, does not seem to have any resolution-change functions! And that's pretty much the situation...I know it's possible, but i don't know how to do it, nor what is the class responsible!

The AppGameContainer class, used on the very start of the game's initialization as of Slick's examples and tutorials, is the only place with any functions for changing the display-mode that I've found so far, but it's only used at the very start, and i haven't found a way to travel back to it from my options menu.

  //This is my implementation of it...
  public static void main(String[] args) throws SlickException {
    AppGameContainer app = new AppGameContainer(new Main());
//    app.setTargetFrameRate(60);
    app.setDisplayMode(800, 600, false);

I can define it as a static global on the Main, but it's probably a (very) bad way to do it...


1 Answer 1


You have to cast the GameContainer object, that is passed in the update method into AppGameContainer, then you can access setDisplayMode... I tested it right now, and it works.

AppGameContainer gc = (AppGameContainer) container;
gc.setDisplayMode(800, 600, false);

But I think you need to use the dev branch of slick, as the "official" version from their page is pretty outdated, and if I'm not mistaken, the resizing capabilities are only supported in the dev branch (but I'm really not sure about this, as I have never used it before).

Here is the wiki page explaining, how you can check out the latest dev version of slick from their repository: Keeping up with the Slick Development Branch

Here is my test class. Should run out of the box. It opens a window in 640x480 resolution, if you press enter, the resolution is changed to 800x600.

Here is my test class:

package ch.digitalmeat.prototypes.slicksim.tests;

import org.newdawn.slick.AppGameContainer;
import org.newdawn.slick.BasicGame;
import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.Input;
import org.newdawn.slick.SlickException;

public class ResizeTest extends BasicGame {

    public static void main(String[] args) throws Exception
        ResizeTest test = new ResizeTest();
        AppGameContainer container = new AppGameContainer(test);
        container.setDisplayMode(640, 480, false);

    public ResizeTest() {
        super("Resize Test");

    public void render(GameContainer container, Graphics g)
            throws SlickException {}

    public void init(GameContainer container) throws SlickException {}

    public void update(GameContainer container, int delta)
            throws SlickException {
            AppGameContainer gc = (AppGameContainer) container;
            gc.setDisplayMode(800, 600, false);

  • \$\begingroup\$ Yes, I'm aware of the "stable" version's outdating, and I'm already using a release from the dev branch. --- The cast idea is really nice! I've already created my own modified class and am already deep into the game's development, but the cast method does work out and, quite sincerely, "I should have thought of that!" is almost making me head-bang the table! =) --- +1 and chosen! \$\endgroup\$ Commented Sep 18, 2012 at 15:22
  • \$\begingroup\$ Yeah, sometimes the answer is so easy you can't see it ;) glad I could help \$\endgroup\$ Commented Sep 19, 2012 at 7:39

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .