Nifty GUI will not call the void method on interact

Hi again :slight_smile:

I’ve recently ran into the problem of my play button not calling the void method it is supposed to when it is clicked. I’m trying to change app states into the gamePlayAppState, but there is no evidence that the method is ever called. I’m pretty sure that my XML code looks good, I’ve made sure the visibleToMouse=“true”, but regardless whenever the play button is clicked it doesn’t enter the startGame() method.

Here’s the XML:
<?xml version=“1.0” encoding=“UTF-8”?>
<nifty xmlns=“
<useStyles filename=“nifty-default-styles.xml” />
<useControls filename=“nifty-default-controls.xml” />
<registerSound id=“btnClickSound” filename=“Sounds/coin.wav” />

&lt;!-- Start Screen --&gt;
&lt;screen id="start" controller=""&gt;

	&lt;!-- This should add the background image --&gt;
	&lt;layer id="background" childLayout="center" width="100%" height="100%"&gt;
		&lt;image filename="Interface/FlightControlBackground.png"&gt;&lt;/image&gt;

	&lt;layer id="foreground" childLayout="vertical"&gt;
		&lt;!-- Empty Spacer Panel to accomodate the background's header --&gt;
		&lt;panel id="panel_top" height="20%" width="100%" align="center"

		&lt;!-- Settings panel --&gt;
		&lt;panel id="panel_settings" height="15%" width="100%" align="center"
			&lt;control name="button" font="aurulent-sans-16.fnt" label="Settings"
				id="SettingsButton" align="center" valign="center" visibleToMouse="true"&gt;
				&lt;interact onClick="gotoScreen(settings)" /&gt;

		&lt;!-- Recalibrate Button --&gt;
		&lt;panel id="panel_recalibrate" height="15%" width="100%" align="center"
			&lt;control name="button" label="Recalibrate" id="RecalibrationButton"
				align="center" valign="center" visibleToMouse="true"&gt;
				&lt;interact onClick="gotoScreen(calibrate)" /&gt;
		&lt;!-- Play Button --&gt;
		&lt;panel id="panel_play" height="15%" width="100%" align="center"
			childLayout="center" visibleToMouse ="true"&gt;
			&lt;control name="button" font="aurulent-sans-16.fnt" label="Play!"
				id="PlayButton" align="center" valign="center" visibleToMouse="true"&gt;
				&lt;interact onClick="startGame()" /&gt;



and the StartScreenAppState (which also acts as the startScreen controller)

public class StartScreenAppState extends AbstractAppState implements ScreenController {
/* AppState specific */
private SimpleApplication app;
private Camera cam;
private Node rootNode;
private AssetManager assetManager;
private InputManager inputManager;
private ViewPort guiViewPort;
private AudioRenderer audioRenderer;
private AppStateManager stateManager;
private boolean flagSoundEnabled = true;
private Listener listener;

private Node sceneNode;
private Nifty nifty;
public boolean isRunning;
StartScreenAppState start;
GamePlayAppState game;

public void initialize(AppStateManager stateManager, Application app) {
	super.initialize(stateManager, app);
	this.stateManager = stateManager; = (SimpleApplication) app; =;
	this.rootNode =;
	this.assetManager =;
	this.inputManager =;
	this.guiViewPort =;
	this.audioRenderer =;;
	this.listener =;



public void bind(Nifty nifty, Screen screen) {
	System.out.println("bind( " + screen.getScreenId() + ")");

private boolean updateWinningScreen = false;

public void onStartScreen() {
	Screen s = nifty.getCurrentScreen();
	if(s.getScreenId().equals("completion")) {
		updateWinningScreen = true;

public void onEndScreen() {
	Screen s = nifty.getCurrentScreen();
	if(s.getScreenId().equals("completion")) {
		updateWinningScreen = false;

private NiftyJmeDisplay niftyDisplay;
private void initNifty() {
	niftyDisplay = new NiftyJmeDisplay(assetManager,
	nifty = niftyDisplay.getNifty();
	nifty.fromXml("Interface/MainMenuLayout.xml", "start", this);

	// attach the nifty display to the gui view port as a processor

public void startGame(Screen screen) {
	start = new StartScreenAppState();
	game = new GamePlayAppState();
	System.out.println("startGame() called... detaching start");
	System.out.println("Start screen detached");
	System.out.println("Game screen attached");



Any help would be much appreciated! Thanks :slight_smile:

Also, I changed startGame(Screen screen) to be just startGame(), right after I posted this. Sorry!

Figured it out.

What was the fix? I ran into the same issue… :confused:

I had changed the location of my screen controllers(put them in an appstate folder within the source) and hadn’t updated the path in the XML documents so it was using a default screen controller instead of the ones that had my custom methods in it. I’d check to make sure the paths that register the screen to the screen controller are correct.