Book Image

JMonkeyEngine 3.0 Cookbook

By : Rickard Eden
Book Image

JMonkeyEngine 3.0 Cookbook

By: Rickard Eden

Overview of this book

Table of Contents (17 chapters)
jMonkeyEngine 3.0 Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Creating an inventory screen


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.

How to do it...

We begin by creating the controls, which are the key components of this method. This can be done by performing the following four steps:

  1. First, we create a new controls file, inventoryControls.xml, with the <nifty-controls> tag.

  2. 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"/>
  3. Then...