Game Development Reference
In-Depth Information
InventoryItem ii = InventoryObjects[i];
t = ii.displayTexture;
int quantity = ii.quantity;
The result of this code is shown as follows:
6. We will compute the total length of all the cells that we want to display. This
is used in the code to render the cells centered in the middle of the screen
horizontally. Recall that the width and height hold the individual cell width and
height:
float totalCellLength = sw - (numcells *
width);
As InventoryMgr loops over all InventoryObjects , we draw a new rect-
angle for each item to be displayed on the screen. To do this, we need to
know the x , y coordinates of the upper-left corner of the rectangle, the height
and width of an individual rectangle, and the texture. The y height doesn't
vary since the inventory is a horizontal row on screen, and the cell height
and width don't vary since the cells are uniform by design. The texture will
change, but we can use the cached value. So, we need to focus our attention
on the x coordinate for a centered array of varying length.
7. It turns out that we can use this formula. The totalCellLength parameter
is the amount of white space horizontally when all the cells are aligned on
one side. If we subtract half of this, we get the starting coordinate that will be
positioned half on the right and half on the left equally. Considering that width
and height are the dimensions of the individual buttons for display and that
i is the loop index for the loop we are discussing, then adding (width*i)
Search WWH ::




Custom Search