This page is a short list of best practices that you should know of when starting to use Nifty GUI. The JME3 tutorials focus on JME3-Nifty integration related details. You will find more features in the Nifty GUI Manual.
-
-
-
-
-
You can build Nifty GUIs using XML or Java syntax. Which one should you choose? The XML and Java syntax are equivalent, so is it an either-or choice? Not quite. You typically use XML and Java together.
Build your basic static UI layout using
XML - it's cleaner to write and read.
Use Java syntax to control the dynamic parts of the
GUI at runtime - it's easier to interact with object-oriented code.
Example: You design two UIs with slightly different
XML layouts for mobile and desktop. If you use the same IDs for equivalent elements, your dynamic Java code works the same no matter which of the two base
XML layout you use it on. This allows you to switch between a phone and a desktop UI by simply swapping one base
XML file.
Use the
jMonkeyEngine SDK New File wizard to create a new
XML file (from the
GUI category, "Empty Nifty File").
The
jMonkeyEngine SDK includes an
XML editor and a special previewer for Nifty
GUI files.
When you open an
XML file, you can switch between
XML Editor and
GUI Preview mode.
Tip: The GUI category in the New File wizard also contains Nifty code samples.
Include the following
XML schema in the first line of your NiftyGUI
XML files
<?xml version="1.0" encoding="UTF-8"?>
<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">
<!-- Your IDE now tells you that one <screen></screen> element is expected here, etc. -->
</nifty>
Now your IDE (including the jMonkeyEngine
SDK) will display extra info and do code completion for the Nifty
GUI API.
If you want to interact with an element, give it an ID (String).
Use transparent ID-less panels as anonymous spacers.
Specify widths and heights in percent to allow the
GUI to scale.
Use * instead of a fixed value to make the element fill the remaining space automatically.
Be cautious when specifying fixed sizes, and test the outcome in various resolutions.
Screens, layers, and panels…
During development (and during a tutorial), the following debug code makes all panels visible. This helps you arrange them and find errors.
nifty.setDebugOptionPanelColors(true);
Before the release, and during testing, set the debug view to false again.