2014-11-24 75 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

相關問題