Game Development Reference
In-Depth Information
Introduction
Nifty GUI is operated using screens. A screen could be, for example, an in-game ( HUD)
heads-up display or the same game's main menu. Screens are built using XML and Nifty's
own set of tags. On each screen, there can be layers that are drawn on top of each other ac-
cording to their order.
On a screen, objects cascade similarly as on a web page, that is, from top to bottom or left
to right, depending on the settings. The following code is an example of what a simple
screen might look like:
<nifty xmlns="http://nifty-gui.sourceforge.net/nifty-1.3.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://nifty-gui.sourceforge.net/
nifty-1.3.xsd http://nifty-gui.sourceforge.net/
nifty-1.3.xsd">
<useStyles filename="nifty-default-styles.xml" />
<useControls filename="nifty-default-controls.xml" />
<registerSound id="showWindow" filename="Sound/Effects/
Beep.ogg" />
<screen id="main"
controller="gui.controller.MainScreenController">
<layer id="layer0" childLayout="absolute"
backgroundColor="#000f">
<!-- add more content -->
</layer>
</screen>
</nifty>
Each screen has a Controller class tied to it. This is the link between the XML and
Java that allows Nifty to control functions in the code and the other way around.
Another important concept is Controls (not to be confused with Controller classes
or jMonkeyEngine's Control interface). Using Controls is a very convenient way to
make screen files smaller and create reusable components. Anyone familiar with, for ex-
ample, components in JSF will see the similarities. It's highly recommended that you be-
Search WWH ::




Custom Search