How to use controllers in Nifty

I’m having trouble understanding how controllers work in Nifty. I tried to get my Player class to modify the gui, but I couldn’t get it and I can’t tell what went wrong. :weary:
Could someone please explain how to use controllers?

Note: I’ve already looked at most of the relevant wiki here. I followed whatever I could, but I couldn’t understand exactly what was going on in some parts.

There’s more than one way to do use Nifty controllers in JME. What I usually do is to create an appstate for each screen. A screen is displayed if and only if its appstate is enabled. Most of the relevant code is here:

1 Like

Ok, but how do I use and implement this into my XML/Java?

1 Like

For each screen, create a BasicScreenController (or an instance of some class that extends it). If you’re using XML, reference the controller’s fully-qualified classname in the screen layout like so:

<nifty xmlns="">
    <screen id="s1" controller="com.github.stephengold.S1Controller">
        <layer childLayout="vertical" backgroundColor="#444f">
1 Like