我正在开发一个monogame项目。当我开始尝试在替代分辨率上测试它时,我遇到了一个奇怪的问题。除了1920 X 1080以外,游戏在全屏上无法正常渲染。
以下是我正在测试的代码:
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
namespace MonogameResTest
{
public class Game1 : Game
{
GraphicsDeviceManager graphics;
SpriteBatch spriteBatch;
Texture2D background;
public Game1()
{
graphics = new GraphicsDeviceManager(this);
Content.RootDirectory = "Content";
}
protected override void Initialize()
{
base.Initialize();
graphics.PreferredBackBufferWidth = graphics.GraphicsDevice.DisplayMode.Width;
graphics.PreferredBackBufferHeight = graphics.GraphicsDevice.DisplayMode.Height;
graphics.IsFullScreen = true;
graphics.ApplyChanges();
}
protected override void LoadContent()
{
spriteBatch = new SpriteBatch(GraphicsDevice);
background = Content.Load<Texture2D>("OnTheWater12");
}
protected override void Draw(GameTime gameTime)
{
GraphicsDevice.Clear(Color.Black);
spriteBatch.Begin();
spriteBatch.Draw(
background,
graphics.GraphicsDevice.Viewport.Bounds,
Color.White);
spriteBatch.End();
base.Draw(gameTime);
}
}
}
当我将计算机的分辨率设置为1920 X 1080时,这样可以正常工作。它按预期呈现覆盖整个屏幕的图像。但是,当我将分辨率更改为其他值时(为了测试,我尝试了1280 X 720,800 X 600和1600 X 900),它渲染到屏幕中心的矩形,而不是渲染在整个屏幕上。我在运行时检查了Viewport.Bounds的值,它显示的值与我设置的分辨率相同。这是怎么回事?