0

I am making a game using XNA and a part of the game involves collecting drops. I have this code below that detects intersection between the character and the item:

//Intersection Code, If the character intersects with the item while the item is showing, run below
if (alive && charRange.Intersects(itemRect))
{
   alive = false; //stop showing the item
   Inv.ItemGot(); //Call the ItemGot class, which adds the item to the inventory screen
}

Another class contains the ItemGot() method, and the code for that is below:

public void ItemGot()
{  // Called from the ItemList class...
   // Sets the background color to black when called
   btnItems[0] = new Panel();
   btnItems[0].BackColor = Color.Black;
}

Basically, when the character intersects with the item rectangle, the color of btnItems[0] should turn from CornflowerBlue (which I set up earlier) to Black. However, the color does not change when the method is called and I don't know why. My code seems to be correct and I've had peers confirm that for me.

Sam Axe
  • 33,313
  • 9
  • 55
  • 89
demiZe
  • 27
  • 6

1 Answers1

0

You are creating a new Panel, but never using it. It's likely you don't want to create a new one because you said the color is already set to CornFlowerBlue.

So, if you already have a Panel setup... ensure you add it to the btnItems list. That way you can access it via btnItems[0].

poy
  • 10,063
  • 9
  • 49
  • 74
  • I got rid of the `btnItems[0] = new Panel();` but now I'm getting a NullReferenceException. Thing is though, I already initialized the panel array in the constructor. – demiZe Jan 05 '14 at 15:20
  • I added details to my answer. – poy Jan 05 '14 at 21:09