chargerstriker
chargerstriker

Reputation: 496

texture2d rectangle XNA wont initialize

I have a rather basic Texture2D name rect and I am just trying to initialize it. It tells me that a field initializer cannot reference the non-static field, method or property "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";
    }

Upvotes: 0

Views: 64

Answers (1)

chargerstriker
chargerstriker

Reputation: 496

Athari's comment was the correct answer - I moved

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

to the method called LoadContent() and it worked.

Upvotes: 2

Related Questions