Game Development Reference
In-Depth Information
And this completes the work on the Insert() method.
Implementing the DisplayInventory method
Let's continue our work by developing InventoryMgr as we program the method
that will display all of the inventory objects on screen by performing the following
steps:
1. The DisplayInventory() method is declared with the following signature:
void DisplayInventory() {
}
2. This method also walks through the collection, but instead of checking the
type of object, it will display a series of GUI buttons on the screen. It will also
show displayTexture for the item in each inventory. As the position of the
inventory cells are relative to the screen, we need to calculate the button po-
sitions based on the screen width and height, as shown in the following code:
float sw = Screen.width;
float sh = Screen.height;
3. We will also store a reference to the texture we will display in each cell, as
shown in the following code:
Texture buttonTexture = null;
4. Then, for clarity, we will store the number of cells in a local integer to display
as shown in the following code:
int totalCellsToDisplay =
inventoryObjects.Count;
5. We will loop over all the cells and extract the texture and quantity in each
InventoryItem in the collection, as shown in the following code:
for (int i = 0; i<totalCellsToDisplay;
i++)
{
Search WWH ::




Custom Search