Now that I have Nifty working as I want it I am left with a question that I am unable to find answers for in the documentation or in this forum (I have looked but it was late last night so please be understanding if I missed something) so I thought I would just ask.
Once you have used code like…
NiftyJmeDisplay niftyDisplay = new NiftyJmeDisplay(assetManager, inputManager, audioRenderer, guiViewPort);
Nifty nifty = niftyDisplay.getNifty();
nifty.fromXml(“Interface/testxml”, “start”, new TestScreenController())
To initialise and interact with an instance of Nifty what is the correct procedure for shutting it down and releasing its resources when it is no longer required?
The reason I want to do this is my planned project will have a very GUI intensive game lobby but the actual game wont need it apart froma very simple hud that I plan to just draw to the screen so ideally I want to clear up on the transition from lobby to game.
Obviously I would need to be able to re-initialize the GUI stuff on going back to the lobby so nothing I do here can prevent this.
As a first stab…
nifty = null;
niftyDisplay = null;
Does this look sensible? Am I missing anything? Do I need to call “nifty.exit();” and if I do what does that actually do?. The JavaDoc for it is empty for it except for the word “exit” - exit what?
calling nifty.exit() will end the current screen and it will make the nifty.update() method return true on the next call which means, yeah, that Nifty is done and ready to quit. so calling nifty.exit() would be the right way to exit nifty.
there are three kinds of resources that are interessting: images, fonts and sounds. everything else shouldn’t be much of a problem and the GC will take care of it. images, fonts and sounds however need special treatment. Nifty already tracks everything it creates internally and is prepared to dispose all of those resources when you call nify.exit(). currently this is however not yet connected so at the moment resources might eventually leak when you exit nifty.