Integrating Nifty GUI: Overlay

  1. Nifty GUI Overlay or Nifty GUI Projection

Define a key (for example escape) that switches the GUI on and off. You can either overlay the running game with the GUI (you will most likely pause the game then), or even project it as a texture onto a mesh texture (but then you cannot click to select). On this page, we look at the overlay variant (more commonly used).

Sample Code

Overlaying the User Interface Over the Screen

This code shows you how to overlay anything on the screen with the GUI. This is the most common usecase.

NiftyJmeDisplay niftyDisplay = new NiftyJmeDisplay(
    assetManager, inputManager, audioRenderer, guiViewPort);
/** Create a new NiftyGUI object */
Nifty nifty = niftyDisplay.getNifty();
/** Read your XML and initialize your custom ScreenController */
nifty.fromXml("Interface/helloworld.xml", "start", new MySettingsScreen(data));
// attach the Nifty display to the gui view port as a processor
guiViewPort.addProcessor(niftyDisplay);
// disable the fly cam
flyCam.setDragToRotate(true);

The MySettingsScreen class is a custom de.lessvoid.nifty.screen.ScreenController in which you implement your GUI behaviour. The variable data contains an object that you use to exchange state info with the game. See Nifty GUI Java Interaction for details on how we created this class.


  1. Nifty GUI Overlay or Nifty GUI Projection
documentation, gui

view online version