For some reason I can not figure out how to quit the app using Nifty.
I have a MenuAppState that extends AbstractAppState and implements (Nifty) Controller
I have a Nifty xml
<?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">
<useStyles filename="nifty-default-styles.xml" />
<useControls filename="nifty-default-controls.xml" />
<screen id="start" >
<layer id="layer" backgroundColor="#003f" childLayout="center" controller="mygame.MenuAppState">
<panel id="panel" height="25%" width="35%" align="center" valign="center" backgroundColor="#f60f" childLayout="center" visibleToMouse="true">
<control name="button" label="Quit" id="QuitButton" align="center" valign="center" >
<interact onClick="quitIt()"/>
</control>
</panel>
</layer>
</screen>
</nifty>
In the MenuAppState I have
public void initialize(AppStateManager stateManager, Application app) {
super.initialize(stateManager, app);
rootApp = (Main) app;
public void quitIt() {
System.out.println("quitIt()");
nifty.exit();
rootApp.stop();
}
I see the output quitIt() in the console so I know it is firing but the app remains running.
Thanks for any help.
-Greg
eth
February 27, 2015, 9:13pm
2
try that:
public void initialize(AppStateManager stateManager, Application app) {
super.initialize(stateManager, app);
rootApp = app;
public void quitIt() {
System.out.println("quitIt()");
nifty.exit();
rootApp.stop();
}
btw: I strongly advice you to use an other gui other than Nifty ( nifty is too old) example: Lemur and tonegodgui
normen
February 27, 2015, 10:28pm
3
I don’t see a reason suggesting Nifty being “too old”.
eth
February 27, 2015, 10:30pm
4
well nifty is very hard to use , and almost nobody use it anymore
Nifty just got updated to 1.4.1 in jmonkey 3.1 and nifty 2.0 is coming up soon, so its still being actively developed. It is a bit hard to use, and lemur and tonegodgui are great. Tonegodgui has not been maintained in the last ~4 months though.
eth
February 27, 2015, 10:41pm
6
^ So if you want to save up time and if you are new then you should use an other gui but that doesn’t mean that nifty gui is bad
normen
February 27, 2015, 10:41pm
7
I don’ think thats correct.
eth
February 27, 2015, 10:46pm
8
Maybe it’s easy for you as you are not a beginner in java and jme3 but for me I find it somehow , har
normen
February 27, 2015, 10:47pm
9
I was referring to the “nobody uses it anymore”. The other point is subjective.
eth
February 27, 2015, 10:48pm
10
Ooh there might be some people who still uses it , but I think most of them love to use their own gui or an easy to use gui
normen
February 27, 2015, 10:50pm
11
I don’t think thats correct.
eth
February 27, 2015, 10:51pm
12
Well No one knows the truth
I figured it out. I was not calling Nifty Correctly
I was using
this.nifty.fromXml("Interface/menuGUI.xml", "start");
instead of
this.nifty.fromXml("Interface/menuGUI.xml", "start", this); //<----- Notice the "this"
…
public class MenuAppState extends AbstractAppState implements ScreenController
Since my MenuAppState was doing the implements Controller but was not being used.
The MenuAppState instance that was being called was not the same instance that I created in my code
In my quit() method rootApp was null and was throwing a null pointer exception that was being eaten by Nifty.
-Greg
pspeed
February 28, 2015, 1:58am
14
…the most evil of programming evils…
1 Like