我正在製作使用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