「Xamarin.Androidで画面の向きを固定する」の版間の差分
ナビゲーションに移動
検索に移動
(→関連項目) |
|||
37行目: | 37行目: | ||
* [[MonoGame]] | * [[MonoGame]] | ||
* [[MonoGame/BGMを再生する]] | * [[MonoGame/BGMを再生する]] | ||
+ | * [[Xamarin.Android/ディスプレイをスリープさせない]] | ||
==参考文献== | ==参考文献== |
2016年3月30日 (水) 09:25時点における版
一般的なアプリでは画面は可変の方がいいのだろうが、MonoGameなどで作るゲームでは画面の向きを固定したいことが多い。
実装:ActivityのRequestedOrientationプロパティをoverrideする
縦方向に固定する場合。
public class Activity1 : AndroidGameActivity
{
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
// 以下のRequestedOrientationプロパティに設定する方法だとダメ。
// 起動時に一瞬だけ横になりMonoGameの初期化ルーチンで画面サイズの情報がバグる。
this.RequestedOrientation = ScreenOrientation.Portrait;
var g = new GameMain();
SetContentView(g.Services.GetService<View>());
g.Run();
}
// RequestedOrientationプロパティをoverrideする方法だと完璧に動くようだ。
public override ScreenOrientation RequestedOrientation
{
get
{
return ScreenOrientation.Portrait;
}
set
{
base.RequestedOrientation = ScreenOrientation.Portrait;
}
}
}