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 开发者_Python百科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;
It was simply a mistake in the code, with the texture got initialized too late, before it should draw it.
Can you load the texture using "textures/disc_96"? I thought it had to use something like "textures\disc_96". Also you assign to texDisc48 twice. So maybe try:
texDisc24 = Content.Load<Texture2D>("textures\\disc_24");
texDisc48 = Content.Load<Texture2D>("textures\\disc_48");
texDisc96 = Content.Load<Texture2D>("textures\\disc_96");
精彩评论