Ending a Nifty-Gui Screen

Hello, it’s David again. I am having a small problem that I have searched for both on the JMonkey site and the Nifty site, but have so far come up blank.

When my application starts, there is a Nifty screen with options and the like, with an animated (via JMonkey) 3d scene going on in the background. When the user clicks “Start Game” I then clear the JMonkey root node, and load the main 3d environment of the game. To make the nifty screen ‘go away’ I tried to call nifty.getCurrentScreen().endScreen(…). This seemed to work at first as the screen does indeed ‘go away’ and I can start playing in my 3d environment. The problem is that the keyboard keys still seem to be bound to that last nifty menu. For example ‘space’ or ‘enter’ will call my callback method on my ScreenController, resulting in my program trying to run though creating the 3d environment all over again as if the “Start Game” button was still visible and selected.

I am obviously missing something. The only thing I could find was this old blog post:


It details about go back and froth between 3d rendering in Slick and 2d rendering in Nifty. I don’t know if 1) this still applies, and if it does if it applies to my situation above and 2) what the equivalent in JMonkey would be.

Thanks for any help,



Have you tried:

  • To totally remove nifty, you can call nifty.exit().
  • If you plan on reusing it to pop up menus in game, you can use nifty.gotoScreen(“empty”) instead and add an empty screen to the nifty element.

    Hope I got it right haha.

That’s what I do.


As far as I know there are no side-effects. I actually think that’s the proper way to close it.

Um… ok yah nifty.exit() works fine, even when afterwords pulling up another menu in game (which yes I will be using). I COULD have sworn I tried that already but WHATEVER I am just glad it worked, even at the expense of posting a silly question :stuck_out_tongue:

Well thanks guys :wink:


Nifty seems to have a big initialization, which is why I think it is probably better not to destroy/recreate it each time you want to pop up a menu.

On the other hand, I’m currently facing a problem where when I wanna pop back my menu screen, it re-triggers the click event of the nifty button from that screen, that closed it… probably linked to click down/click release or something? So maybe you are better avoiding this potential problem haha.

I guess one could try to .hide() the lowest level layer (or even the nifty tag if it has an id, or maybe even add one)?

Hmm interesting. I will have to run some tests later on the exact impact of re-initializing Nifty.

can you post your code ? Maybe i can help

try to go to a empty screen in nifty then do what you want

1 Like

I guess they did sort that out in seven years…

1 Like