【MonoGame】画面解像度を変更したい

2015-06-30 12:02:17

  1. MonoGame
  2. 開発
MonoGameで画面解像度を変えたいときって、どこを変更するんだ! と思ったら、プログラム上で指定するのですね・・(XNAやってない勢)ということでメモです。
[スポンサードリンク]
{GraphicsDeviceManagerの変数に設定する必要があるのでProgram.csから呼ばれる、Gameクラスを継承したクラスのコンストラクタで指定しましょう! またまたデフォルトの「Game1」クラスだと仮定して進めます。}
public Game1() {
    graphics = new GraphicsDeviceManager(this);
    graphics.PreferredBackBufferWidth = 1280;
    graphics.PreferredBackBufferHeight = 720;
    Content.RootDirectory = "Content";
}

「PreferredBackBufferWidth」と「PreferredBackBufferHeight」に好きな値を設定しましょう。 これだけです!

Games1.cs

using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;

namespace sample
{
    public class Game1 : Game
    {
        private GraphicsDeviceManager _graphics;
        private SpriteBatch _spriteBatch;

        public Game1()
        {
            _graphics = new GraphicsDeviceManager(this);
            _graphics.PreferredBackBufferWidth = 1280;   //【今回追加したコード】
            _graphics.PreferredBackBufferHeight = 720;   //【今回追加したコード】
            Content.RootDirectory = "Content";
            IsMouseVisible = true;
        }

        protected override void Initialize()
        {
            // TODO: Add your initialization logic here

            base.Initialize();
        }

        protected override void LoadContent()
        {
            _spriteBatch = new SpriteBatch(GraphicsDevice);

            // TODO: use this.Content to load your game content here
        }

        protected override void Update(GameTime gameTime)
        {
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape))
                Exit();

            // TODO: Add your update logic here

            base.Update(gameTime);
        }

        protected override void Draw(GameTime gameTime)
        {
            GraphicsDevice.Clear(Color.CornflowerBlue);

            // TODO: Add your drawing code here

            base.Draw(gameTime);
        }
    }
}
[スポンサードリンク]

コメント

[スポンサードリンク]
[スポンサードリンク]