Well, I finnaly got a grasp of how to use the ScalableGame class.
Then again, @Kev, both the docs and the example code were painfully lacking on info regarding the resolution-change during runtime. "It will be done automatically" was something very far from my thoughts and at last for me, it made it VERY counter-intuitive to implement.
Well, that aside, it turns out all that is needed for the visual+input rescaling is to set the AppGameContainer with:
Code:
app = new AppGameContainer(new ScalableGame(new Main(), optimumWidth /*int*/, optimumHeight /*int*/, keepRatio /*Boolean*/));
Instead of:
Code:
app = new AppGameContainer(new Main());
And it will do the rescaling for me on every resolution-change, and all be happy for ever and ever; Or actually, until I push the "Exit" button and terminate the app...
I still have one issue tough; I get the visual+input combo under-scaled (smaller than the size of the window) if I setDisplayMode with values under those I've set as optimum for the ScalableGame.
==========
As for the changing of the resolution, the problem is exactly that, setting the new resolution.
Yes, I can define a public static method on the main, just as I'm doing to have access to the class; That's not the issue.
The issue is "Why does the GameContainer not have those directly accessible?", or, in a code example, why do I (we) have to use this:
Code:
public class State_OptionsMenu extends BasicGameState {
/*...*/
public void update(GameContainer container, StateBasedGame game, int delta) throws SlickException {
/*...*/
if (btn_PrevResolution.isMouseOver(mouseX, mouseY)) {
if (input.isMousePressed(Input.MOUSE_LEFT_BUTTON)) {
DisplayMode temp = getPrevResolution();
Main.app.setDisplayMode(temp.getWidth(), temp.getHeight(), Display.isFullscreen()); //Or a call to a "do the same" public static method also @ the Main class.
}
}
/*...*/
}
/*...*/
}
Instead of something like this:
Code:
public class State_OptionsMenu extends BasicGameState {
/*...*/
public void update(GameContainer container, StateBasedGame game, int delta) throws SlickException {
/*...*/
if (btn_PrevResolution.isMouseOver(mouseX, mouseY)) {
if (input.isMousePressed(Input.MOUSE_LEFT_BUTTON)) {
DisplayMode temp = getPrevResolution(); //Returns a DisplayMode with the next lower resolution, from the ones available.
container.setDisplayMode(temp.getWidth(), temp.getHeight(), container.isFullscreen());
/*Another option that is lacking, even on AppGameContainer, is to set the DisplayMode more directly. Like "container.setDisplayMode(getPrevResolution(), container.isFullscreen());"*/
}
}
/*...*/
}
/*...*/
}
???
