[Nifty] Controller Problem


I have a little Problem with the Controllers.

I used

getNiftyDisplay().getNifty().fromXml(“Interface/MainMenu.xml”, “start”, controller);

getNiftyDisplay().getNifty().fromXml(“Interface/Game.xml”, “start”, controller);

etc. before. But it’s really slow.

Now I wanted to use it like that:

getNiftyDisplay().getNifty().fromXml(“Interface/Game.xml”, “start”, controller); // ← Startscreen is empty

getNiftyDisplay().getNifty().gotoScreen(“MainMenu”); // Menuscreen

getNiftyDisplay().getNifty().gotoScreen(“Game”); //gamescreen (dialogs)

But I have for all of them own Controller.

I can use it like that:


getNiftyDisplay().getNifty().fromXml(“Interface/GameScreen.xml”, “MainMenu”);

But if I use only gotoScreen it doesn’t work.

Is there a possibilty to change the active ScreenController?

Edit: Okay… I only changed one thing:

I made the class where i use


to the ScreenController and now Its working fine :smiley:


why don’t you just define the controller through the XML? If you already have an XML condiguration file for the screens. That’s what I do. The only real reason I see for setting the screencontroller through java like you are doing is if the controller needs some setting / data preconfiguring it. If that’s not the case, defining it in XML is just as easy, if not more easy.

I’m having a controller issue myself. I noticed in my log I’m getting

“INFO: Missing ScreenController for screen [start] using DefaultScreenController() instead but this might not be what you want.”

I’ve tried doing:

nifty.registerScreenController(new MyScreenController())

nifty.fromXml(“screen.xml”, “start”, new MyScreenController())

Is there a specific place MyScreenController needs to be in relation to my assets/Interface/screen.xml file?


Yes, in the screen definition.

Like in mine:


<screen id="start" controller="mythruna.MainMenuState">


It uses that to either instantiate a new one or match it up by class to the one passed on loadXml().

Edit: to make the XML show up.

lol. That was the third example I posted, but I guess the editor yanked it >_<

< screen id=“start” controller=“MyScreenController” >

I guess I should clarify though, by “specific place” I mean the actual file itself that defines my custom controller. I have my screen.xml in /assets/Interface/screen.xml, but I have my custom controller in /lib/samples/nifty/my_screen_controller.rb

So I’m wondering if jME looks in a specific place for the controller in relation to the xml file. I tried loading everything through a custom builder, and the controller loads fine that way, but I would like to use the XML way…

should I be using nifty.loadXml() instead of nifty.fromXml() ?

There is no package?

screen id=“start” controller=“MyScreenController”


JME and nifty don’t “look” for classes anywhere. They do the equivalent of Class.forName( theControllerName ).

hmmm :confused: Ruby doesn’t use packages… I’ve got a confession… I don’t know Java… at all… lol… This has been my gateway to learning it (because this is the fun way!) I’ll checkout what Class.forName() does, and see if I can replicate that.


You will need the fully qualified class name (including its package) in the controller="" attribute.

I presumed MyScreenController() was a Java class because you were passing it to nifty in a previous call… if not then you may have some problems.

Yeah, I write most of my examples on here in Java for others to understand it a bit better. I can normally do the conversions, but only if I understand what’s going on behind the scenes. This one is a bit tricky because it looks for the package rather than a path.

hmm… Maybe I can emulate the package… :smiley: