如何在Adobe AIR中调整舞台大小以便在全屏时坐在中心?

时间:2014-04-13 23:58:33

标签: actionscript-3 actionscript air adobe

我已经浏览了整个网络,试图找出如何调整Adobe Air应用视口矩形的大小。而我似乎无法弄明白。

我想要做的就是使用Adobe AIR制作一款游戏,以便在"退格"键被按下(现在进行测试)它使游戏进入FULL_SCREEN。

游戏目前在stage.displayState.NORMAL中启动,我将来要实现一个选项以启用FULL_SCREEN。

然而,我似乎无法弄清楚的问题是当FULL_SCREEN在Adobe AIR中处于活动状态时,如何让我的舞台在屏幕中央对齐。

我想要的是当你进入FullScreen时,舞台位于中心,就像发布的第一张图片一样。

http://cl.ly/image/190t3u3U1C3e < - 这是adl启动时所有内容都集中的游戏。

enter image description here < - 当应用进入FULL_SCREEN时,舞台与TOP_LEFT对齐。

这是我的Main.AS处理舞台设置。当进入FullScreen时,如何将要设置的舞台对齐。喜欢伊萨克的绑定?

[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;
    }
}

感谢。

1 个答案:

答案 0 :(得分:2)

设置全屏时,必须将stage.scaleMode设置为StageScaleMode.NO_SCALE,并将stage.align设置为""
在代码中:

stage.displayState = StageDisplayState.FULL_SCREEN_INTERACTIVE;
stage.scaleMode = StageScaleMode.NO_SCALE
stage.align = ""