This evening I switched switched from TWL to Nifty to give it a try. I experienced some of the same issues as you. I did get it working though. The documentation isn't great and there's no complete example at the end, so it's hard to know exactly what you're supposed to do at a glance. Below I've included the function I implemented to properly set up Nifty.
As the documentation states(see manual), your main game class is supposed to extend NiftyOverlayGame
, or one of the other classes it lists, as I answered in your other question.
One of the functions you need to override is initGameAndGUI
and I believe this is where your issue originates from. This is how I did it properly:
protected void initGameAndGUI(GameContainer gc) throws SlickException {
renderDevice = new SlickRenderDevice(gc);
soundDevice = new SlickSoundDevice();
inputSystem = new SlickSlickInputSystem(new PlainSlickInputSystem());
timeProvider = new LWJGLTimeProvider();
gui = new Nifty(renderDevice, soundDevice, inputSystem, timeProvider);
initNifty(gc);
}
Where these objects were defined inside my main class as (I'll include the imports as well for reference):
import de.lessvoid.nifty.Nifty;
import de.lessvoid.nifty.slick2d.NiftyOverlayGame;
import de.lessvoid.nifty.slick2d.input.PlainSlickInputSystem;
import de.lessvoid.nifty.slick2d.input.SlickSlickInputSystem;
import de.lessvoid.nifty.slick2d.render.SlickRenderDevice;
import de.lessvoid.nifty.slick2d.sound.SlickSoundDevice;
import de.lessvoid.nifty.slick2d.time.LWJGLTimeProvider;
import de.lessvoid.nifty.spi.input.InputSystem;
import de.lessvoid.nifty.spi.sound.SoundDevice;
...
public final class MainGame extends NiftyOverlayGame {
Nifty gui;
SoundDevice soundDevice;
SlickRenderDevice renderDevice;
InputSystem inputSystem;
TimeProvider timeProvider;
...
Hopefully setting up your code similar to this should help you get on the right track (if you haven't figured this out already).
initNifty()
. Could you please edit the question and add the code where you add the game state of the game (that must not happen more then once) and where your launch your game? \$\endgroup\$