我想创建所有单独的食物对象,这些对象已被玩家拾取但不知何故我不断收到错误;对象引用未设置为对象的实例。
int indexFood;
public Sprite(Graphics paper)
{
while (indexFood < 50)
{
foodArray[indexFood] = new Food();
indexFood++;
}
}
public void DrawFood(Graphics drawArea)
{
foreach (Food food in foodArray)
{
food.DrawFood(drawArea);
food.XPos = 8;
food.XPos += 32;
}
}
这是foodClass方法代码:
public void DrawFood(Graphics drawArea)
{
drawArea.FillEllipse(new SolidBrush(Color.Yellow), xPosFood, yPosFood, size, size);
}