对象引用未设置为对象的实例。图形设备管理器

时间:2015-08-12 10:01:38

标签: c# xna

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 Space_Shooter
{


public class Game1 : Microsoft.Xna.Framework.Game
{
    GraphicsDeviceManager graphics;

    SpriteBatch spriteBatch;

    public Game1()
    {

        graphics.IsFullScreen = false;
        graphics.PreferredBackBufferWidth = 800;
        graphics.PreferredBackBufferHeight = 950;
        this.Window.Title = "XNA Space Shooter";

        graphics = new GraphicsDeviceManager(this);
        Content.RootDirectory = "Content";
    }


    protected override void Initialize()
    {


        base.Initialize();
    }


    protected override void LoadContent()
    {
        // Create a new SpriteBatch, which can be used to draw textures.
        spriteBatch = new SpriteBatch(GraphicsDevice);

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


    protected override void UnloadContent()
    {

    }


    protected override void Update(GameTime gameTime)
    {

        if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
            this.Exit();



        base.Update(gameTime);
    }


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



        base.Draw(gameTime);
    }
}
}

错误显示在“graphics.isFullscreen = false;”我不知道该怎么做..我认为代码可能是针对早期的XNA框架,但我想知道如何解决这个问题以使用当前的XNA框架,因为如果有人这样做,这样做会更聪明我知道如何解决这个问题然后请告诉我..这篇文章也很多,因为我的大部分帖子都是代码,它不会让我发布它,直到我有更多的细节,所以希望我不需要写更多..反正有人请帮忙!!!

1 个答案:

答案 0 :(得分:0)

public class Game1 : Microsoft.Xna.Framework.Game
{
GraphicsDeviceManager graphics;

SpriteBatch spriteBatch;

public Game1()
{

    graphics.IsFullScreen = false;
    graphics.PreferredBackBufferWidth = 800;
    graphics.PreferredBackBufferHeight = 950;
    this.Window.Title = "XNA Space Shooter";

    graphics = new GraphicsDeviceManager(this);
    Content.RootDirectory = "Content";
}

我在尝试设置其值后给图形赋值... 我应该:

public class Game1 : Microsoft.Xna.Framework.Game
{
GraphicsDeviceManager graphics;

SpriteBatch spriteBatch;

public Game1()
{
    graphics = new GraphicsDeviceManager(this);
    graphics.IsFullScreen = false;
    graphics.PreferredBackBufferWidth = 800;
    graphics.PreferredBackBufferHeight = 950;
    this.Window.Title = "XNA Space Shooter";


    Content.RootDirectory = "Content";
}