Fullscreen mode is widely available in games and apps that want to display as much content as possible, such as video players.
In this tutorial I'll show you how to toggle fullscreen mode using OpenFL.
There are three fullscreen modes in OpenFL, similarly to Flash API. They are all described in the StageDisplayState class using static properties.
The modes are: FULL_SCREEN, FULL_SCREEN_INTERACTIVE and NORMAL.
These values can be used both to check the current display mode and to set it.
The NORMAL value is set when the application is displayed in its usual state, not fullscreen.
The idea of FULL_SCREEN and FULL_SCREEN_INTERACTIVE being two separate values came from Flash player, the only difference being that FULL_SCREEN_INTERACTIVE allows more user interaction in full screen mode (such as text input).
Note that to use FULL_SCREEN_INTERACTIVE when targeting Flash, the HTML embed code needs to be properly constructed to allow this behavior.
The values are set to the displayState property of the current stage:
Lib.current.stage.displayState = StageDisplayState.NORMAL;
The values can be used in conditionals as well, as shown in this fullscreen toggling example:
private function toggleFullscreen() {
if(Lib.current.stage.displayState != StageDisplayState.FULL_SCREEN_INTERACTIVE){
Lib.current.stage.displayState = StageDisplayState.FULL_SCREEN_INTERACTIVE;
}else {
Lib.current.stage.displayState = StageDisplayState.NORMAL;
}
}
To start the application in fullscreen mode, you can use the fullscreen attribute of the window tag in application.xml:
<window fullscreen="true" />
The toggle function will still work even if you use the xml approach.