无论窗口大小/位置如何,都将项目保持在相同的显示器位

时间:2014-11-24 17:43:23

标签: actionscript-3 air

我正在尝试用全屏创建游戏。

当我在全屏模式下向stage添加对象时,我希望退出时相对于监视器保持相同的坐标(例如1000像素)全屏模式。

离开全屏模式时,如何让对象移动到同一位置?

1 个答案:

答案 0 :(得分:1)

开始使用:

这些方面的内容是您需要做的事情:

stage.align = StageAlign.TOP_LEFT;  //you'll need to running a top-left no-scale swf for this to work
stage.scaleMode = StageScaleMode.NO_SCALE;

var itemPoint:Point = new Point(150,150);  //the point on the monitor the object should reside

//call this anytime the item needs to be redrawn (eg when the window changes size or position)
function updatePos(e:Event = null){
    //We need to also account for the chrome of the window 
    var windowMargin:Number = (stage.nativeWindow.bounds.width - stage.stageWidth) * .5; //this is the margin or padding that between the window and the content of the window
    var windowBarHeight:Number = stage.nativeWindow.bounds.height - stage.stageHeight - windowMargin; //we have to assume equal margin on the left/right/bottom of the window

    item.x = itemPoint.x - stage.nativeWindow.x - windowMargin;
    item.y = itemPoint.y - stage.nativeWindow.y - windowBarHeight;
}

stage.nativeWindow.addEventListener(NativeWindowBoundsEvent.MOVE, updatePos); //we need to listen for changes in the window position
stage.nativeWindow.addEventListener(NativeWindowBoundsEvent.RESIZE, updatePos); //and changes in the window size

//a click listener to test with
stage.addEventListener(MouseEvent.CLICK, function(e:Event):void {
    if(stage.displayState == StageDisplayState.FULL_SCREEN_INTERACTIVE){
        stage.displayState = StageDisplayState.NORMAL;
    }else{
        stage.displayState = StageDisplayState.FULL_SCREEN_INTERACTIVE;
    }
});

updatePos();