texture2d矩形XNA不会初始化

时间:2014-10-24 21:07:06

标签: c xna

我有一个相当基本的Texture2D名称rect,我只是想初始化它。它告诉我,字段初始值设定项不能引用非静态字段,方法或属性“graphics”

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

    //my variables and stuff I delcare

    //texture we can render
    Texture2D myTexture;

    //set coords to draw the spirte
    Vector2 spritePos = new Vector2(300.0f, 330.0f);

    //some info about motion
    Vector2 spriteSpeed = new Vector2(0f, 0f);

    KeyboardState oldState;
    double boost = 15;

    //boost level rectange this is the issue below+
    Texture2D rect = new Texture2D(graphics.GraphicsDevice, 80, 30);

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

1 个答案:

答案 0 :(得分:2)

Athari的评论是正确答案 - 我感动了

    //boost level rectange this is the issue below+
    Texture2D rect = new Texture2D(graphics.GraphicsDevice, 80, 30);

到名为LoadContent()的方法,它起作用了。