Time for action – Getting oriented

From our previous applications we know that we can accomplish this by performing a quick orientation change within the Awake() method of our application:

function Awake()
{
  iPhoneSettings.screenOrientation = iPhoneScreenOrientation.Landscape;
}

In previous examples we put our functions in the Start() method, but we are putting this call in the Awake() method. The reason for this is that we want this script, and the orientation settings, to be processed as soon as the scene is loaded, but before the joystick script tries to determine where to put the joysticks. If we didn't do this the position of the joysticks would be too close together as their positions would have been derived from the portrait orientation.

If you were to run your application now you would find that the application will hold to a single screen orientation, however, when you rotated you would get a black outline that rotates with the screen. This black outline represents the iOS keyboard interface rotating with the device. To prevent this from happening you need to lock the keyboard so that it is in the same orientation with the application.

Key Class/Methods

Description

iPhoneSettings.screenOrientation

Gets/Sets the orientation of the device

iPhoneScreenOrientation

Enumerated type of the possible device orientations

iPhoneKeyboard.autorotateXXXX

Sets whether or not the iPhoneKeyboard will rotate to a particular orientation when the device changes orientation

void Awake()
{
  iPhoneSettings.screenOrientation = iPhoneScreenOrientation.Landscape;
  iPhoneKeyboard.autorotateToPortrait = false;
  iPhoneKeyboard.autorotateToPortraitUpsideDown = false;
}

What just Happened?

We have configured the game so that it will default to landscape orientation when it starts. In addition, the game will do what the users expect and you won't have the graphical glitch of the iOS keyboard trying to adjust for the device orientation.

Next, our design calls for a touch interface with two joystick areas with the one on the left acting as the movement stick and the one on the right acting as the rotation joystick. We will use these to capture user interactions and drive our character around the game world.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.138.124.143