2014-11-24 77 views
0

我正在尝试使用全屏创建游戏。不管窗口大小/位置如何将项目保持在同一显示器位置

当我以全屏模式将对象添加到stage时,我希望它保持在相对于显示器的相同坐标(例如1000像素),当我退出全屏模式时。

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

+0

,我不明白你的问题。你是说你想要物品保持在相同的相对位置(到显示器),而不管窗口位置/大小吗? – BadFeelingAboutThis 2014-11-24 17:46:04

+0

是的,这就是我的意思 – 2014-11-24 17:49:05

+0

这是一个相当复杂的问题(虽然当然可以)。你试过什么了? – BadFeelingAboutThis 2014-11-24 17:53:46

回答

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(); 
+0

你能解释一下这行代码的作用吗? – 2014-11-24 18:31:03

+0

stage.displayState =(stage.displayState == StageDisplayState.FULL_SCREEN_INTERACTIVE?StageDisplayState.NORMAL:StageDisplayState.FULL_SCREEN_INTERACTIVE); – 2014-11-24 18:31:37

+0

这只是切换全屏模式。这是一个内联if语句。因此,如果当前displayState是全屏,请将其指定为“normal”,否则,将其指定为“全屏交互式”。我编辑了这个问题,使它成为一个常规的if语句,如果有帮助的话(它们完全一样) – BadFeelingAboutThis 2014-11-24 18:33:38

相关问题