In my project, I am unable to switch to another ScreenState when I click a button. Using actionListeners, I don’t have this problem.
After clicking the Start Button, I switch to a new Nifty screen (“hud”). The corresponding AppState does, however, not change.
Here’s my code (in StartScreenState):
[java]
public StartScreenState startScreenState;
public RunningScreenState runningScreenState;
public StartScreenState(SimpleApplication app){
this.rootNode = app.getRootNode();
this.viewPort = app.getViewPort();
this.guiNode = app.getGuiNode();
this.assetManager = app.getAssetManager();
}
//Nifty GUI ScreenControl methods
public void bind(Nifty nifty, Screen screen) {
this.nifty = nifty;
this.screen = screen;
}
public void onStartScreen() { }
public void onEndScreen(){ }
@Override
public void initialize(AppStateManager stateManager, Application app) {
super.initialize(stateManager, app);
this.app=(SimpleApplication) app;
this.rootNode = this.app.getRootNode();
this.assetManager = this.app.getAssetManager();
this.stateManager = this.app.getStateManager();
this.inputManager = this.app.getInputManager();
this.viewPort = this.app.getViewPort();
}
@Override
public void setEnabled(boolean enabled) {
// Pause and unpause
super.setEnabled(enabled);
if(enabled){
// init stuff that is in use while this state is RUNNING
rootNode.attachChild(localRootNode);
guiNode.attachChild(localGuiNode);
// call custom methods…
} else {
// take away everything not needed while this state is PAUSED
rootNode.detachChild(localRootNode);
guiNode.detachChild(localGuiNode);
}
}
public void startGame(){
nifty.gotoScreen(“hud”);
startScreenState.setEnabled(false);
runningScreenState.setEnabled(true);
}
@Override
public void update(float tpf) {
}
}
[/java]
In the main file, the following same lines respond correctly to an actionListener (so the screenstates are correctly registered etc.):
[java]
nifty.gotoScreen(“hud”);
startScreenState.setEnabled(false);
runningScreenState.setEnabled(true);
[/java]
So, does anyone know why it isn’t working this time? Thanks in advance.