How can i change from full screen to window and viceversa?
Change screen mode
zachwlewis
(Zachary Lewis)
#2
Here’s Adobe’s documentation on fullscreen-mode: Working with full-screen mode.
There are several considerations to take into account when running a FlashPunk game fullscreen. By default, the Engine does not scale, so you’ll want to force your stage render mode to scale, or else you’ll be in fullscreen mode with a tiny game. Again, refer to the above link which explains how to do this.
rostok
(rostok)
#3
here’s my code:
public class Main extends Engine
{
public function Main()
{
...
}
override public function init():void
{
stage.addEventListener(Event.RESIZE, stageResizeHandler);
Input.define("toggle_fullscreen", Key.F12);
...
}
public function fitToStage(keepAspect:Boolean = true):void
{
if (!keepAspect) {
this.scaleX = FP.stage.stageWidth / (FP.width * FP.screen.scaleX);
this.scaleY = FP.stage.stageHeight / (FP.height * FP.screen.scaleY);
}
else {
var scale:Number;
if (FP.screen.width / FP.screen.height < FP.stage.stageWidth / FP.stage.stageHeight) {
scale = FP.stage.stageHeight / (FP.height * FP.screen.scaleY);
this.x = FP.stage.stageWidth / 2 - (FP.halfWidth * FP.screen.scaleX) * scale;
this.y = 0;
}
else {
scale = FP.stage.stageWidth / (FP.width * FP.screen.scaleX);
this.x = 0;
this.y = FP.stage.stageHeight / 2 - (FP.halfHeight * FP.screen.scaleY) * scale;
}
this.scaleX = scale;
this.scaleY = scale;
}
}
private function stageResizeHandler(e:Event):void
{
fitToStage();
}
public function switchFullScreen(keepAspect:Boolean=true):void
{
if (FP.stage.displayState == StageDisplayState.NORMAL) {
FP.stage.displayState = StageDisplayState.FULL_SCREEN;
} else {
FP.stage.displayState = StageDisplayState.NORMAL;
}
}
override public function update():void
{
if (Input.released("toggle_fullscreen")) switchFullScreen(true);
...
super.update();
}
}
not only it switches to full screen but also keeps aspect ratio when projector window is being resized.