Search code examples
c#xnatexture2d

Assigning a Texture2D to an existing Texture2D


I am currently messing with C# XNA 4.0, but I am having some problems assigning a Texture2D to an existing Texture2D. An example of the code shown below:

    protected override void LoadContent()
    {
        spriteBatch = new SpriteBatch(GraphicsDevice);

        texDisc48 = Content.Load<Texture2D>("textures/disc_24");
        texDisc48 = Content.Load<Texture2D>("textures/disc_48");
        texDisc96 = Content.Load<Texture2D>("textures/disc_96");
    } 
// Random place in the code
texCurrentDisc = texDisc96;

But when I am trying to use the texCurrentDisc in etc Draw, I get the following error: This method does not accept null for this parameter. Parameter name: texture. The texCurrentDisc is just initalized as: Texture2D texCurrentDisc;


Solution

  • It was simply a mistake in the code, with the texture got initialized too late, before it should draw it.