MonoGame (Xamarin.Android)で画面の向きを指定する
MonoGame (Xamarin.Android)プロジェクトを新規作成すると必ずエントリポイントとなるActivityクラスが作られる。
このActivityクラスの「ScreenOrientation属性」を変更する。
基本的には至って普通のXamarin.Androidでの方法と同じである。
- 初期値は「ScreenOrientation.FullUser」となっておりスマホの回転にあわせグルグル回る。
- 横画面に固定したい場合は「ScreenOrientation.Landscape」を指定する。
- 縦画面に固定したい場合は「ScreenOrientation.Portrait」を指定する。
[Activity(Label = "Game1",
MainLauncher = true,
Icon = "@drawable/icon",
Theme = "@style/Theme.Splash",
AlwaysRetainTaskState = true,
LaunchMode = LaunchMode.SingleInstance,
ScreenOrientation = ScreenOrientation.Portrait,
ConfigurationChanges = ConfigChanges.Orientation |
ConfigChanges.KeyboardHidden |
ConfigChanges.Keyboard |
ConfigChanges.ScreenSize)]
public class GameActivity : AndroidGameActivity
{
}