为什么设置分辨率在单机游戏中不起作用?

问题描述

我发现了类似的问题here。我将代码放入了contructor方法中,但对我来说不起作用。

graphics.PreferredBackBufferWidth = 400;
graphics.PreferredBackBufferHeight = 300;

如果我在Initialize()函数中设置分辨率并调用ApplyChanges()可以工作,但是正如他所说,不建议在Initialize()函数中设置分辨率,最好将其放在构造函数

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

namespace MagicAdventure
{
    public class GameManager : Game
    {
        private GraphicsDeviceManager graphics;
        private SpriteBatch spriteBatch;
        private Player player;

        public static GameManager Instance { get; private set; }
        public static Viewport Viewport { get { return Instance.GraphicsDevice.Viewport; } }
        public static Vector2 ScreenSize { get { return new Vector2(Viewport.Width,Viewport.Height); } }

        public GameManager()
        {
            graphics = new GraphicsDeviceManager(this);
            Content.RootDirectory = "Content";

            graphics.PreferredBackBufferWidth = 400;
            graphics.PreferredBackBufferHeight = 300;

            IsMouseVisible = true;

            Instance = this;
        }

        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
            //AssetsManager.Load(Content);

            player = new Player();
        }

        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
            //DebugDraw.Update(gameTime);
            //Input.Update(gameTime);

            //player.Update(gameTime);

            base.Update(gameTime);
        }

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

            // Todo: Add your drawing code here
            //spriteBatch.Begin(SpriteSortMode.BackToFront);
            //player.Draw(_spriteBatch);

            //DebugDraw.Draw(_spriteBatch);
            //spriteBatch.End();

            base.Draw(gameTime);
        }
    }
}

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)