Render Nifty after everything else

I made the following class to render GIF images:

/**
 * Loads a GIF file, and renders its frames on an update()
 *
 * @author taylorshuler
 */
public class Animation2D {

    private final GifDecoder decoder = new GifDecoder();
    private final AWTLoader loader = new AWTLoader();
    private final SimpleApplication app;
    private int frameIndex;
    private float frameDelay = decoder.getFrameCount() > 0 ? decoder.getDelay(frameIndex) : 0;

    public Animation2D(SimpleApplication app, String path) {
        this.app = app;

        TextureKey key = new TextureKey(path, false);
        AssetInfo info = app.getAssetManager().locateAsset(key);

        try (InputStream stream = info.openStream()) {
            decoder.read(stream);
        } catch (IOException err) {
            KnightRite.LOGGER.log(Level.SEVERE, "Count not find texture file!", err);
        }
    }

    public void update(Picture pic, float tpf) {
        frameDelay -= tpf;

        if (frameDelay < 0) {
            frameDelay = decoder.getDelay(frameIndex) / 1000F;

            Texture2D tex = new Texture2D(loader.load(decoder.getFrame(frameIndex), true));
            pic.setTexture(app.getAssetManager(), tex, true);

            if (frameIndex < decoder.getFrameCount() - 1) {
                ++frameIndex;
            } else {
                frameIndex = 0;
            }
        }
    }
}

I would like to render this and then my Nifty GUI stuff. How would I do so?

I assume you care about rendering order because you want Nifty to appear in front of (obscuring) the GIFs. If so, simply use a parent that’s in the rootNode tree, such as rootNode itself. Nifty puts its spatials in the guiNode tree, which is overlays rootNode spatials in the render.

See https://jmonkeyengine.github.io/wiki/jme3/advanced/hud.html

Nifty actually doesn’t put anything in any JME scene graph. It’s a separate scene processor and doesn’t use any JME Spatials to render.

I don’t remember what Nifty setup code looks like and the original post doesn’t include that.

When it renders depends on which ViewPort nifty was added to.

1 Like

Thanks for the hint! I eventually figured it out, as follows:

        // init guiNode contents

        // init nifty display

        // draw nifty over guiNode contents
        Camera niftyCam = new Camera(settings.getWidth(), settings.getHeight());
        ViewPort niftyViewPort = renderManager.createPostView("Nifty Default", niftyCam);
        niftyViewPort.addProcessor(niftyDisplay);
        niftyViewPort.setClearFlags(false, false, false);
1 Like

Does this cause the Nifty display to be rendered twice?