Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I am having a problem adjusting the size of the screen while using the ScalableGame class from the Slick2D library.

I would like the background and objects (images and graphic shapes) to adjust to fit the screen size whenever the display size changes.

This is how the state looks by default. I can change the screen size, but the objects do not.

appGameContainer = new AppGameContainer(
     new ScalableGame(new AppStateController(), Settings.video.getWidth(), Settings.video.getHeight(), true)
);
appGameContainer.setDisplayMode(Settings.video.getWidth(), Settings.video.getHeight(), Settings.video.isFullScreen());
appGameContainer.start();

enter image description here

If I add a value of 100 to the width and height in the ScalableGame constructor call, the state looks like this:

appGameContainer = new AppGameContainer(
     new ScalableGame(new AppStateController(), Settings.video.getWidth() + 100, Settings.video.getHeight() + 100, true)
);
appGameContainer.setDisplayMode(Settings.video.getWidth(), Settings.video.getHeight(), Settings.video.isFullScreen());
appGameContainer.start();

enter image description here

If I add a value of 100 to the width and height of the display, the state looks like this:

appGameContainer = new AppGameContainer(
     new ScalableGame(new AppStateController(), Settings.video.getWidth(), Settings.video.getHeight(), true)
);
appGameContainer.setDisplayMode(Settings.video.getWidth() + 100, Settings.video.getHeight() + 100, Settings.video.isFullScreen());
appGameContainer.start();

enter image description here

Here are some more screenshots that demonstrate the problem:

enter image description here enter image description here enter image description here

Do you know what might be causing the problem?

share|improve this question

1 Answer 1

Found a link that helped me, I'm not sure we're having the same problem but it's worth looking at as my game is working perfectly now.

http://slick.ninjacave.com/forum/viewtopic.php?t=6184

your render method should look something like this...

public void render(GameContainer gc, Graphics g)
{
    float desiredWidth = whatever;
    float desiredHeight = whatever;
    float originalWidth = whatever;
    float originalHeight = whatever;

    g.scale(desiredWidth / originalWidth, desiredHeight / originalHeight);

    //render all your images and whatnot

    g.scale(1,1);
}
share|improve this answer
    
Alright so you think, that I should, before I call each graphic object at the first line of a render method, call g.scale(); but how do you calculate x, y ? –  nellykvist Nov 5 '13 at 16:02
    
Ye but, what would be desiredWidth, desiredHeight ? –  nellykvist Nov 10 '13 at 21:43
    
Whatever you want the height/width to be after you scale it. –  user2144536 Nov 12 '13 at 16:22
    
Check my topic post, where I show you problem I have with scaling. –  nellykvist Nov 13 '13 at 12:33

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.