我正在制作使用XNA的游戏,游戏的一部分涉及收集滴剂。我具有低于此代码检测字符和项目之间的交叉:即使条件得到满足,BackColor也不会改变
//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
}
另一类包含ItemGot()
方法,以及用于该代码是下面:
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;
}
基本上,字符相交时对于项目矩形,btnItems[0]
的颜色应该从CornflowerBlue
(我之前设置)变为Black
。但是,调用方法时颜色不会更改,我不知道为什么。我的代码似乎是正确的,我已经有同行确认了我。
你在'ItemGot()'中设置了一个断点来确认它被调用吗? – Andrew
@Andrew是的,因为btnItems [0]被填充,ItemGot()被调用 – demiZe
你在'ItemGot()'中初始化'btnItem [0]'。 'btnItem [0]'等于'panel 1'吗? – user3093781