Problem screen transition Nifty

I have three screens and two controllers that I have set up and can transition through them in one direction but having a problem going back to a previous screen.

When I start the app I set up my states MenuState and RunState and attach them to the statemanager.

[java]stateManager.attach(runState);
stateManager.attach(menuState); [/java]

In the menustate I do this:

NiftyJmeDisplay niftyDisplay = new NiftyJmeDisplay(app.getAssetManager(),
app.getInputManager(),
app.getAudioRenderer(),
app.getGuiViewPort());
[java]//nifty.getNiftyMouse().enableMouseCursor(“default”);
nifty = niftyDisplay.getNifty();
nifty.fromXml(“Interfaces/screen.xml”, “start”, this);
/nifty.addScreen(“menu”, nifty.getScreen(“menu”));/
nifty.addScreen(“runState”, nifty.getScreen(“runState”));
app.getGuiViewPort().addProcessor(niftyDisplay);[/java]

As you can see I have tried using addScreen to the nifty instance but this doesn’t change my issue.

I can move from the start screen (which allows the user to log on) to the menu screen which allows some choices before moving to the run state. Once in the runstate I get a null pointer exception when trying to go back to the menu state.

[java]private void leaveScreen()
{
System.out.println(“Leaving Run Screen”);
MenuState menuState = state.getState(MenuState.class);
this.setEnabled(false);
menuState.setEnabled(true);
System.out.println(nifty);
nifty.gotoScreen(“menu”);
//TODO save state here
}[/java]

the goToScreen method throws an NullPointerException.

In the bind method I do this

[java]this.nifty = nifty;
this.screen = screen;
System.out.println(nifty + " " + screen + " in RunState");[/java]

and the println gives me[java] de.lessvoid.nifty.Nifty@43dcc7b5 de.lessvoid.nifty.screen.Screen@3f5f15b in RunState[/java]

but the println from leaveScreen prints a null for the nifty variable.

How can I fix this? It appears that when I call leaveScreen I am calling on a different object that has not had bind called but the only place I create a runstate is in main and attach it to the statemanger. When I move forwards from the menustate I get that instance from the statemanager.

I think I have the answer to this and it is that I haven’t addedd my runstate as a processor.

After doing this I am unable to return back to the runstate. Can anyone tell me why?

When I am in the runstate and and setEnabled to false and true for the menu state then goToScreen(menustate) my run state loop is still running.

I wasn’t reseting the variable I was using to determine moving from the menu to run states. Setting this as well as isEnabled solved my problem.

1 Like