I've looked all over the web to try and figure out how to resize an Adobe Air apps viewport rectangle. And I can't seem to figure it out.
What I'm trying to do is make a game with Adobe AIR so that when the "backspace" key is pressed (for testing right now) it enables the game to go into FULL_SCREEN.
The game currently launches in stage.displayState.NORMAL, and I'm going to implement an option in the future to enable FULL_SCREEN.
However, the problem that I can't seem to figure out is how to get my stage to align in the center of the screen when FULL_SCREEN is active with Adobe AIR.
What I want is that when you go into FullScreen the stage is in the center like the first image posted.
<- This is the game when the adl launches with everything being centered.
<- And when the app goes into FULL_SCREEN, the stage aligns to the TOP_LEFT.
This is my Main.AS that handles the Stage Setup. How can I align the stage to be set in the middle when it goes into FullScreen. Like Binding of Issac?
[SWF(frameRate="60", width="1920", height="1080", backgroundColor="#000000")]
public class Main extends MovieClip {
public var _starling:Starling;
public static var screenWidth:Number = 0.0;
public static var screenHeight:Number = 0.0;
public function Main() {
addEventListener(Event.ADDED_TO_STAGE, stageSetup);
}
private function stageSetup(e:Event):void {
removeEventListener(Event.ADDED_TO_STAGE, stageSetup);
stage.displayState = StageDisplayState.NORMAL;
var rect:Rectangle = new Rectangle(0, 0, stage.fullScreenWidth, stage.fullScreenHeight);
screenWidth = stage.fullScreenWidth > 1920 ? 1920 : stage.fullScreenWidth;
screenHeight = stage.fullScreenHeight > 1080 ? 1080 : stage.fullScreenHeight;
Starling.handleLostContext = false;
_starling = new Starling( GameEngine, stage);
_starling.antiAliasing = 1;
_starling.start();
_starling.showStats = true;
stage.addEventListener(KeyboardEvent.KEY_DOWN, escKeyOverride);
stage.addEventListener(KeyboardEvent.KEY_DOWN, enableFullScreen);
stage.addEventListener(Event.RESIZE, resize);
}
private function enableFullScreen(e:KeyboardEvent):void {
if (e.keyCode == 8) {
stage.displayState = StageDisplayState.FULL_SCREEN_INTERACTIVE;
stage.scaleMode = StageScaleMode.EXACT_FIT;
}
else {
//build in button listener for settings to resize back to normal
stage.scaleMode = StageScaleMode.EXACT_FIT;
}
}
private function escKeyOverride(e:KeyboardEvent):void {
if (e.keyCode == 27) {
e.preventDefault();
}
}
private function resize(e:Event):void {
var viewPortRectangle:Rectangle = new Rectangle();
viewPortRectangle.width = stage.stageWidth;
viewPortRectangle.height = stage.stageHeight;
Starling.current.viewPort = viewPortRectangle;
_starling.stage.stageWidth = stage.stageWidth;
_starling.stage.stageHeight = stage.stageHeight;
}
}
Thanks.
When you set the fullscreen, you must set the stage.scaleMode
to StageScaleMode.NO_SCALE
, and set the stage.align
to ""
In code:
stage.displayState = StageDisplayState.FULL_SCREEN_INTERACTIVE;
stage.scaleMode = StageScaleMode.NO_SCALE
stage.align = ""