Image: supported orientations
The default orientation can be set either in the project wizard when the project is being creating or anytime later in project properties window. Default orientation is usually used when the application starts.
The orientation can be set during the second step of the project wizard. You can select any of the three supported orientations.
The default project orientation can be set also in the project properties window. Right click on the project name in the navigation panel and click on the Application tap.
Some projects can run on several device orientations. All mobile devices contain accelerometer sensor. According to the data from the accelerometer sensor operation system can send information about the device’s position to the Moscrif application. There is no need to do any calculations in the applications associated with recognition of the device tilt.
All the developer needs to do is just set the supported orientations and then properly handle the event that is raised when the orientation changes. By default, only one orientation is supported. If the application can manage more orientations all supported orientations must be set to the game’s orientations property.
Example: setting supported orientations
function start() { super.start(); // load graphical resources GFX.load(); // load sound and musics SFX.load(); // supported orientations this.orientation = [#portrait, #landscape-left, #landscape-right]; this.bg = GFX.background; // add menu scene this.push(new MenuScene()); }
When device’s orientation is changed the application received an onOrientationChanged event. The event’s parameter is the new device orientation. When the device orientation is changed also the values of System.height and System.width variables are replaced, as well as a position of x and y axis.
In the sample program the onOrientationChanged event causes a change of the background image and position of all controls.
Game.instance.onOrientationChanged = function(orientation) { this super.replaceControls(orientation); } … function replaceControls(orientation) { currentOrientation = orientation; this._singlePlayer.x = System.width / 2; this._singlePlayer.y = 8 * System.height / 10; this._multiPlayer.x = System.width / 2; this._multiPlayer.y = 9 * System.height / 10; if (currentOrientation == #portrait) Game.instance.bg = GFX.background; else Game.instance.bg = GFX.backgroundLandscape; }
Note: In emulator, the change of device orientation can be simulated using the Ctrl+F11 shortcut.