I have my .xml file set up like this: [xml]<layer childLayout=“center”>
<panel height=“20%” width=“25%” align=“right” valign=“bottom” childLayout=“center” visibleToMouse=“true” >
<interact onClick=“options()” />
<text font=“Interface/Fonts/Arial.fnt” color="#000f" text=“Options” align=“center” valign=“top” />
</panel>
</layer>[/xml]
In java I have a public void options() loop that has a print line but when I click the nifty element the line doesn’t print. How can I fix this?
Most likely you haven’t set the controller up properly in the XML or you are using a specific controller instance and haven’t supplied it to nifty.
yeh post your nifty lines in your java code, and your screen xml tag
Menu.java simpleinitapp loop: [java] public void simpleInitApp() {
setDisplayStatView(false);
setDisplayFps(false);
NiftyJmeDisplay niftyDisplay = new NiftyJmeDisplay(assetManager,
inputManager,
audioRenderer,
guiViewPort);
nifty = niftyDisplay.getNifty();
nifty.fromXml("Interface/Menu.xml", "start", this);
// attach the nifty display to the gui view port as a processor
guiViewPort.addProcessor(niftyDisplay);
inputManager.setCursorVisible(true);
flyCam.setEnabled(false);
flyCam.setDragToRotate(true);
}[/java]
Nifty screen controller: [xml]<screen id="start" controller="com.vivagamestudio.Menu">[/xml]
Anybody?
Nobody will help me?
It’s not that nobody will help you. Everything is in the Nifty tutorials.
Your controller (Menu.java) doesn’t seem to be the one you use when you start the screen
nifty.fromXml(“Blahblah”, “start”, this);
In this case “this” is your game’s “Main” class I presume, which is NOT Menu.java.
If you want to use Menu as the screen controller, pass that to “fromXml(…)” and not “this”.
@madjack said:
It's not that nobody will help you. Everything is in the Nifty tutorials.
Your controller (Menu.java) doesn't seem to be the one you use when you start the screen
nifty.fromXml("Blahblah", "start", this);
In this case "this" is your game's "Main" class I presume, which is NOT Menu.java.
If you want to use Menu as the screen controller, pass that to "fromXml(...)" and not "this".
How would I pass that to fromXml?
@ifence9 said:
How would I pass that to fromXml?
[java]com.vivagamestudio.Menu menu = new com.vivagamestudio.Menu() ;
nifty.fromXml("Interface/Menu.xml", "start", menu);
[/java]
Instantiating objects is not jME specific, this is basic java programming.
Thank you for the info. I didn’t think about making a new object for it.
It is still not working…
Fixed it. The controller was set to the wrong package. Thank you all for your help.