C# 我的GraphicsDeviceManager不支持全屏显示';不能使用XNA
我要回来和XNA做个游戏,但我有个问题。 当我从我的C# 我的GraphicsDeviceManager不支持全屏显示';不能使用XNA,c#,visual-studio-2010,visual-studio-2012,xna,fullscreen,C#,Visual Studio 2010,Visual Studio 2012,Xna,Fullscreen,我要回来和XNA做个游戏,但我有个问题。 当我从我的GraphicsDeviceManager中使用IsFullScreen并将其置于游戏控制器中的true时,我的游戏不会进入全屏,而是保持窗口状态 我查找了IsFullScreen的值,当我在游戏构造函数中时,它的值为true,但当我查看更新或绘制中的值时,值为false 当我按下F时,我试图将该值设置为true,但没有任何更改。 我还尝试使用了切换全屏,IsFullScreen的值发生了很大的变化,但什么也没有发生。 我试图设置Preferr
GraphicsDeviceManager
中使用IsFullScreen
并将其置于游戏控制器中的true
时,我的游戏不会进入全屏,而是保持窗口状态
我查找了IsFullScreen
的值,当我在游戏
构造函数中时,它的值为true,但当我查看更新
或绘制
中的值时,值为false
当我按下F
时,我试图将该值设置为true,但没有任何更改。
我还尝试使用了切换全屏
,IsFullScreen
的值发生了很大的变化,但什么也没有发生。
我试图设置PreferredBackBuffer
宽度和高度,然后我需要使用ApplyChanges
,每次调用它时,它都会将IsFullScreen
设置为false
。即使它改变了窗口大小,它也不是全屏的,所以不是我想要的
这是我的密码,如果你看到什么,请告诉我,欢迎任何建议
using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
namespace MyGames
{
/// <summary>
/// This is the main type for your game
/// </summary>
public class SpaceInvader : Game
{
private readonly GraphicsDeviceManager graphics_;
private KeyboardState oldKeyboardState_;
private KeyboardState newKeyboardState_;
private SpriteBatch spriteBatch_;
private Ship playerShip_;
public SpaceInvader()
{
graphics_ = new GraphicsDeviceManager(this);
Content.RootDirectory = "Content";
// Set device frame rate to 60 fps.
TargetElapsedTime = TimeSpan.FromSeconds(1 / 60.0);
graphics_.PreferredBackBufferWidth = 480;
graphics_.PreferredBackBufferHeight = 268;
}
protected override void Initialize()
{
playerShip_ = new Ship(new Vector2(Window.ClientBounds.Width / 2, Window.ClientBounds.Height - 150), new Vector2(10,10));
base.Initialize();
}
protected override void LoadContent()
{
// Create a new SpriteBatch, which can be used to draw textures.
spriteBatch_ = new SpriteBatch(GraphicsDevice);
playerShip_.LoadContent(Content);
}
protected override void UnloadContent()
{
// TODO: Unload any non ContentManager content here
}
protected override void Update(GameTime gameTime)
{
newKeyboardState_ = Keyboard.GetState();
// Allows the game to exit
if (newKeyboardState_.IsKeyDown(Keys.Escape))
Exit();
// TODO: Add your update logic here
playerShip_.Update(Window, newKeyboardState_, oldKeyboardState_);
base.Update(gameTime);
}
protected override void Draw(GameTime gameTime)
{
if (oldKeyboardState_.IsKeyDown(Keys.F) && newKeyboardState_.IsKeyUp(Keys.F))
graphics_.ToggleFullScreen();
graphics_.GraphicsDevice.Clear(Color.CornflowerBlue);
//set rendering back to the back buffer
// Draw the sprite.
spriteBatch_.Begin(SpriteSortMode.BackToFront, BlendState.AlphaBlend);
playerShip_.Draw(spriteBatch_);
spriteBatch_.End();
base.Draw(gameTime);
oldKeyboardState_ = newKeyboardState_;
}
}
}
我需要改用:
SpaceInvader game = new SpaceInvader();
game.Run();
我不知道它是否正在更改某些内容,但它会在第二个大括号上抛出异常NullReferenceException未处理
EDIT2:
我在网上看到,它允许我使用VisualStudio 2010,但它不是在谈论VisualStudio 2012。
在阅读之后,我想这是正常的,因为我没有做任何类似的事情来安装XNA
我想这是VS2012的问题。请尝试下面的代码,而不是切换布尔值:
isFullscreen()=true;
哈哈。小错误,您需要添加:this.graphics.ApplyChanges()代码>。我也做过同样的事请理解,每次您想要更改某些内容时都需要这样做,在调用之前不会有任何更改。我将关闭已回答的主题,因为我说过要使用XNA,您需要使用VS2010
我在XNA的下载页面上看到,它允许我使用VisualStudio 2010,但它并不是在谈论VisualStudio 2012。在阅读了这些页面之后,我想这是正常的,因为我没有做任何类似的事情来安装XNA
我想这是VS2012的问题。我试着编译了你的代码,效果很好。你一定没有显示相关内容。好吧,我想这很奇怪,我刚刚尝试了VS2010,它工作得很好。如果你想在Visual Studio 2012中使用XNA,我建议使用此应用程序正确设置依赖项。另一个可能性是将用户首选项保存在设置文件中,并在启动时加载。许多游戏需要重新启动才能更改图形设置,这没什么好羞愧的。谢谢,是的,我认为你是对的,但目标仍然是了解XNA下发生了什么。嗯,不,我说我试过了,每次调用时它都会将图形。IsFullScreen
设置为false。所以它不会进入全屏。我真的认为VS2012有一个问题,我需要使用VS2010,或者使用一些其他的应用程序,比如Helion在我帖子的评论中说的,或者像我在帖子的链接中说的那样做一些技巧。
SpaceInvader game = new SpaceInvader();
game.Run();