Android rotation issue : Landscape left only

While working on a game called Drainpipe, we had a requirement to display the game always in Landscape left mode. We set proper attributes in our AndroidActivity class :

[Activity(Label = "DrainPipe",
Icon = "@drawable/icon",
ScreenOrientation = ScreenOrientation.SensorLandscape,
MainLauncher = true,
LaunchMode = LaunchMode.SingleTask,
ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation)]

And also in the constructor,


this.DefaultOrientation = WaveEngine.Common.Input.DisplayOrientation.LandscapeLeft;
this.SupportedOrientations = WaveEngine.Common.Input.DisplayOrientation.LandscapeLeft;

And also in manifest file,


<activity android:name="com.google.android.gms.ads.AdActivity" android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize" android:theme="@android:style/Theme.Translucent" />

All these changes, made sure that the game is only playable in Landscape mode but still when you tilt the phone it still allows the app to rotate it to Landscape Right. Since the game heavily depends on user movements based on accelerometer, it was kind of ruining the experience. When too much tilt happens screen rotates back to Landscape right and make the game not playable any more. Even disabling the rotation in android phone does not help.

To stop that finally found a hack, where you need to override the RequestedOrientation and set that to Landscape.


public override ScreenOrientation RequestedOrientation
{
get
{
return base.RequestedOrientation;
}
set
{
base.RequestedOrientation = ScreenOrientation.Landscape;
}
}

This seems to work like a charm. Now no matter how much user tilt the phone, it never goes back to Landscape right.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s