Actionscript 3 无论窗口大小/位置如何,将项目保持在同一监视器位置
我正在尝试创建一个全屏游戏 当我在全屏模式下向Actionscript 3 无论窗口大小/位置如何,将项目保持在同一监视器位置,actionscript-3,air,Actionscript 3,Air,我正在尝试创建一个全屏游戏 当我在全屏模式下向阶段添加对象时,我希望它在退出全屏模式时相对于监视器保持相同的坐标(例如1000像素) 离开全屏模式时,如何使对象移动到同一位置?要开始: 您需要做的是以下几点: 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;
阶段
添加对象时,我希望它在退出全屏模式时相对于监视器保持相同的坐标(例如1000像素)
离开全屏模式时,如何使对象移动到同一位置?要开始:
您需要做的是以下几点:
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();
我不明白你的问题。你是说不管窗口的位置/大小,你都希望项目保持在相同的相对位置(相对于显示器)?是的,这就是我的意思。这是一个相当复杂的问题(尽管确实可以)。到目前为止,您尝试了什么?您能解释一下这行代码的作用吗?stage.displayState=(stage.displayState==StageDisplayState.FULL\u SCREEN\u INTERACTIVE?StageDisplayState.NORMAL:StageDisplayState.FULL\u SCREEN\u INTERACTIVE);这只是切换全屏模式。这是一个内联if语句。因此,如果当前显示状态为全屏,则将其分配为
normal
,否则,将其分配为全屏交互式
。我编辑了这个问题,使之成为一个常规的if语句,如果这有帮助的话(他们做完全相同的事情),我用if语句更好地理解它。非常感谢