如何解决为什么设置分辨率在单机游戏中不起作用?
我发现了类似的问题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 举报,一经查实,本站将立刻删除。