Can't get Nifty to change screens

I’m having difficulty getting Nifty to change screens to and from a loading screen.

I have two screens attached to two states - gameState and loadState. When the gameState needs to do some loading, I call the loading screen in the Main class:

[java]public void startLoadScreen()
{
loadState.setEnabled(true);
gameState.setEnabled(false);
nifty.gotoScreen(“loading”);
}[/java]

This works fine and the loading screen appears. When the gameState finishes doing its business, it calls this:

[java]public void endLoadScreen()
{
gameState.setEnabled(true);
loadState.setEnabled(false);
nifty.gotoScreen(“game”);
}[/java]

But it doesn’t work - the loading screen won’t go away.

As far as I know, the states are all loaded and registered correctly, there are no errors.

Even more confusing is that I have a menu screen bound to the ESC key that uses the same method for switching screens - and it works fine.

Any ideas?

Do you get any nifty warnings? does that screen exist? did you add its XML file? Is the bind method called of your game screen? Put some breakpoints down and find the cause of the issue

Also take a look at the recent article I published on how we handle this in HeroDex:

http://hub.jmonkeyengine.org/2013/04/the-herodex-gui-working-in-jme3/

Sorry, I thought it may just have been a simple issue of me not using gotoScreen correctly.

I get no Nifty warnings; the screen exists; I’ve added the XML; the bind method is being called on the game screen.

What I’ve found is that if I do track the currentState as a variable of my Main class and update it in endLoadScreen():

[java]public void endLoadScreen()
{
gameState.setEnabled(true);
loadState.setEnabled(false);
nifty.gotoScreen(“game”);
currentScreen = “game”;
}[/java]

And then add a check in the update loop:

[java]public void SimpleUpdate(float tpf)
{
if (!nifty.getCurrentScreen().getScreenId().equals(currentScreen))
nifty.gotoScreen(currentScreen);
}[/java]

Then the screen changes correctly.

So I’m clearly misunderstanding something fundamental about how Nifty and app states work.

You are probably trying to change screen while the start screen and/or end screen effects are already running from another screen transition.

That’s mentioned in the article I linked you to…