I moved to a new URL! Check it out!

Adobe AIR Window Scaling

Adobe AIR Window Scaling
Over the past week I added some menus and options to my Global Game Jam game remake. I'm doing this super early on in the game's life because having some awesome polished menus makes it feel like a "real" game, which motivates me to work on it more. One of the first things I did for the game options was window scaling. The game natively runs at 320 x 240, so obviously players are going to want some various scaling options unless they really want to run it at 1x and barely see the game on their screens that are now probably 4000 pixels wide.

The awesome thing about working in AIR is that it will automagically resize the game's window to the size of the flash stage, so all I have to do is set the stage width and the stage height and the window will resize to match. However, there are some funky issues that can arise.

The flash stage has different scaling modes that you can use. There's EXACT_FIT, NO_BORDER, NO_SCALE, and SHOW_ALL. For the case of this game, I'm using EXACT_FIT after I resize the window. The reason for this is so that players with super huge monitor set ups can scale the window themselves.

This was actually a problem with Offspring Fling until the lastest update. I had a player that had a desktop width of over 4000 pixels because of their multimonitor set up. They couldn't play in fullscreen mode because it would scale across both monitors, and they couldn't play in windowed mode because it was too tiny. Changing the window mode to EXACT_FIT made it so anyone can scale the window to whatever size they want. I could've also used SHOW_ALL, which would maintain the game's aspect ratio as it scaled, but some users wanted to stretch the game to fill their entire monitor. (WHY?!)

These scaling modes can have some wacky effects on your stage resizing code though. Originally I was trying to use SHOW_ALL to maintain the aspect ratio, and this was causing some weird problems. My code looked like this:
//Change the window to 2x mode.
FP.stage.scaleMode = StageScaleMode.SHOW_ALL;
FP.stage.stageWidth = 640;
FP.stage.stageHeight = 480;
But this had some really strange results. The window would end up getting super tall, but staying at 320 pixels wide. After an hour of frustration and trying a lot of different things, I figured out that AIR will actually scale my window the very moment I changed the stageWidth! So what ended up happening was the window would be scaled from 320 x 240 to 640 x 240, and then when it tried to update itself to 640 x 480, it would freak out because the aspect ratio was changed when I set it to 640 x 240. The solution was to change the scale mode to NO_SCALE before doing any changes to the stageWidth or stageHeight. Afterwards I'm free to change the scaling mode back to EXACT_FIT or SHOW_ALL. This applies more to the SHOW_ALL scale mode, and I don't think the EXACT_FIT mode has any issues with it. The new code for changing my window size to 2x looks like this:
if (FP.stage.displayState == StageDisplayState.FULL_SCREEN_INTERACTIVE) {
FP.stage.displayState = StageDisplayState.NORMAL;
}
FP.stage.scaleMode = StageScaleMode.NO_SCALE;

FP.stage.stageWidth = 640;
FP.stage.stageHeight = 480;

FP.stage.scaleMode = StageScaleMode.EXACT_FIT;
The only other thing I add here is a check to see if I need to go back to StageDisplayStage.NORMAL if I happen to be in fullscreen mode prior to the switch. I could also switch that EXACT_FIT to SHOW_ALL if I need to.

I couldn't find anything about this when I was searching, so I just hope that maybe this info saves someone a headache in the future!

Comments

Albert
Albert
Thank You for this tutorial it was very essential.
Posted April 20th 2018 1:00 AM
new comment!

Post your comment!

Name
Email
Comment