Slick Forums

Discuss the Slick 2D Library
It is currently Sat May 25, 2013 5:59 pm

All times are UTC




Post new topic Reply to topic  [ 3 posts ] 
Author Message
PostPosted: Wed Aug 26, 2009 9:40 pm 
Offline
Regular
User avatar

Joined: Thu Dec 18, 2008 6:07 pm
Posts: 238
Location: Bournemouth, UK
I've created my game to be scalable.

Code:
AppGameContainer container = new AppGameContainer(new ScalableGame(new InversePolarity(), WIDTH, HEIGHT, true));


where WIDTH and HEIGHT are the normal width and height of my game (used for game logic like how to control the games camera)

Now, when I change my display mode from 320x240 to 640x480, the game is rendered in the center of the container (at 320x240), is not resized to fit the container, and the rest of the game's container is black.

Can anybody else confirm this as a bug?

_________________
- Gwinnell (irc.freenode.net, irc.chatspike.net)
- Game Jolt Moderator


Last edited by Gwinnell on Fri Sep 18, 2009 1:42 pm, edited 2 times in total.

Top
 Profile  
 
 Post subject:
PostPosted: Sun Sep 13, 2009 4:18 pm 
Offline
Regular
User avatar

Joined: Thu Dec 18, 2008 6:07 pm
Posts: 238
Location: Bournemouth, UK
Image of resize bug here:
http://www.netbin.co.uk/external/image?id=560050212408595

If I call reinit() on the container, it resizes the game how it's meant to, but I don't want my container to, well... reinit! ;-)

_________________
- Gwinnell (irc.freenode.net, irc.chatspike.net)
- Game Jolt Moderator


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 18, 2010 3:40 pm 
Offline
Regular

Joined: Wed Dec 09, 2009 6:56 pm
Posts: 132
I just discovered the same issue. I didn't notice until now because I was either starting out directly in window mode or directly in full screen mode with ScalableGame. As long as you do that, everything looks fine. But, if you set up your application to toggle between window mode and full screen mode, your issue occurs. This should be listed as a bug.

Edit: The cause appears to be because ScalableGame works out the amount of scaling and the amount of black padding in the init() method. There should be a way to force it recompute those values.

Edit 2: As an experiment, I copied the code of ScalableGame into ScalableGame2 and I added this method:

Code:
  public void containerSizeChanged(GameContainer container) {
      targetWidth = container.getWidth();
      targetHeight = container.getHeight();
      if (maintainAspect) {
         boolean normalIsWide = (normalWidth / normalHeight > 1.6 ? true : false);
         boolean containerIsWide = ((float) targetWidth
          / (float) targetHeight > 1.6 ? true : false);
         float wScale = targetWidth / normalWidth;
         float hScale = targetHeight / normalHeight;

         if (normalIsWide & containerIsWide) {
            float scale = (wScale < hScale ? wScale : hScale);
            targetWidth = (int) (normalWidth * scale);
            targetHeight = (int) (normalHeight * scale);
         } else if (normalIsWide & !containerIsWide) {
            targetWidth = (int) (normalWidth * wScale);
            targetHeight = (int) (normalHeight * wScale);
         } else if (!normalIsWide & containerIsWide) {
            targetWidth = (int) (normalWidth * hScale);
            targetHeight = (int) (normalHeight * hScale);
         } else {
            float scale = (wScale < hScale ? wScale : hScale);
            targetWidth = (int) (normalWidth * scale);
            targetHeight = (int) (normalHeight * scale);
         }

      }

      container.getInput().setScale(normalWidth / targetWidth,
                             normalHeight / targetHeight);

      int yoffset = 0;
      int xoffset = 0;

      if (targetHeight < container.getHeight()) {
         yoffset = (container.getHeight() - targetHeight) / 2;
      }
      if (targetWidth < container.getWidth()) {
         xoffset = (container.getWidth() - targetWidth) / 2;
      }
      container.getInput().setOffset(-xoffset / (targetWidth / normalWidth),
                              -yoffset / (targetHeight / normalHeight));
  }


I maintain a reference to both the AppGameContainer and the ScalableGame2 with my game class. After changing the size with the methods of AppGameContainer, I call the above method. This hack works quite well.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 0 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group