In this recipe, we'll create an inventory screen, which is very common, mostly in RPGs. To do this, we'll use the Droppable
and Draggable
components in Nifty and create an InventoryItem
class to help us differentiate different the types of items (and hence, where they can be attached). This time, we'll use both XML to create the static components and the Java Builder interface to build the inventory (or backpack) slots. The reason is that in many games, the amount of inventory a character has varies.
We begin by creating the controls, which are the key components of this method. This can be done by performing the following four steps:
First, we create a new controls file,
inventoryControls.xml
, with the<nifty-controls>
tag.Inside this, we first define
<controlDefinition name="itemSlot">
with the following content:<control name="droppable" backgroundColor="#fff5" width="64px" height="64px" margin="1px" childLayout="center"/>
Then...