Game Development Reference
In-Depth Information
Getting ready
Let's look at how to initialize Nifty in an application. We start off by defining a new Ap-
pState to handle our Nifty functions. We can call it NiftyAppState and have it ex-
tend AbstractAppState .
In the initialize method, we need to create the Nifty display with the following line of
code, giving Nifty access to various functionalities within the application and telling it to
render o in the GUI view:
NiftyJmeDisplay niftyDisplay = new
NiftyJmeDisplay(app.getAssetManager(),
app.getInputManager(),
app.getAudioRenderer(),
app.getRenderManager().getPostView("Gui
Default"));
We should also store the Nifty instance in the class for use later, using niftyDis-
play.getNifty() . With this done, we need to add niftyDisplay as a processor to
the same view we just specified, using the following code:
app.getRenderManager().getPostView("Gui
Default").addProcessor(niftyDisplay);
The last thing that needs to be done before Nifty could show anything is to tell it what to
draw. We do this with nifty.fromXml and pass the XML file to be used as well as the
name of the screen (if several screens are stored in the same XML).
Search WWH ::




Custom Search