ページ「マウス」と「MonoGameで解像度を設定する」の間の差分
(ページ間の差分)
ナビゲーションに移動
検索に移動
(→概要) |
|||
1行目: | 1行目: | ||
− | + | == 実装例 == | |
+ | MonoGameで画面解像度を変更するにはGraphicsDeviceManagerインスタンスのPreferredBackBufferWidthプロパティおよびPreferredBackBufferHeightプロパティで設定を行う。 | ||
− | + | なお、[[Xamarin.Mac]]などでウインドウ表示であれば設定値がそのまま使われるが、[[Xamarin.Android]]などでフルスクリーン環境の場合はディスプレイ側が対応するもっとも近い解像度に自動変更されるので注意すること。 | |
− | + | <source lang="csharp"> | |
− | [[ | + | public class Game1 : Game |
− | + | { | |
− | + | GraphicsDeviceManager graphics; | |
− | |||
− | |||
− | == | + | public Game1() |
− | + | { | |
− | + | graphics = new GraphicsDeviceManager(this); | |
+ | Content.RootDirectory = "Content"; | ||
+ | } | ||
− | + | protected override void Initialize() | |
− | + | { | |
+ | // TODO: Add your initialization logic here | ||
+ | graphics.PreferredBackBufferWidth = 360; | ||
+ | graphics.PreferredBackBufferHeight = 240; | ||
+ | graphics.ApplyChanges(); | ||
+ | |||
+ | base.Initialize(); | ||
+ | } | ||
+ | } | ||
+ | </source> | ||
+ | なお、解像度を要望する(反映させる)GraphicsDeviceManager.ApplyChangesメソッドは以下の点に注意すること。 | ||
+ | * Gameクラスのコンストラクタ内で呼び出しても無反応 | ||
+ | * 明示的に呼び出す場合はGameクラスのInitializeメソッドが呼ばれたタイミングで利用可能となる | ||
+ | * 暗黙的にGameクラスのbase.Initialize()の中でも実行されている模様 | ||
+ | *: base.Initializeメソッドを呼び出した時点で[[ゲームループ]]が走り出すので注意。 | ||
== 関連項目 == | == 関連項目 == | ||
− | * [[ | + | * [[:category: MonoGame|MonoGameカテゴリ]] |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
== 参考文献 == | == 参考文献 == | ||
33行目: | 38行目: | ||
{{stub}} | {{stub}} | ||
+ | |||
+ | [[category: MonoGame]] |
2017年3月9日 (木) 10:26時点における版
実装例
MonoGameで画面解像度を変更するにはGraphicsDeviceManagerインスタンスのPreferredBackBufferWidthプロパティおよびPreferredBackBufferHeightプロパティで設定を行う。
なお、Xamarin.Macなどでウインドウ表示であれば設定値がそのまま使われるが、Xamarin.Androidなどでフルスクリーン環境の場合はディスプレイ側が対応するもっとも近い解像度に自動変更されるので注意すること。
public class Game1 : Game
{
GraphicsDeviceManager graphics;
public Game1()
{
graphics = new GraphicsDeviceManager(this);
Content.RootDirectory = "Content";
}
protected override void Initialize()
{
// TODO: Add your initialization logic here
graphics.PreferredBackBufferWidth = 360;
graphics.PreferredBackBufferHeight = 240;
graphics.ApplyChanges();
base.Initialize();
}
}
なお、解像度を要望する(反映させる)GraphicsDeviceManager.ApplyChangesメソッドは以下の点に注意すること。
- Gameクラスのコンストラクタ内で呼び出しても無反応
- 明示的に呼び出す場合はGameクラスのInitializeメソッドが呼ばれたタイミングで利用可能となる
- 暗黙的にGameクラスのbase.Initialize()の中でも実行されている模様
- base.Initializeメソッドを呼び出した時点でゲームループが走り出すので注意。