Hi,
The codes are almost the same from the end of this link http://www.jmonkeyengine.com/forum/index.php?topic=13996.0
I modified the code a bit and wrote a new xml.
For some reason I always get this error when I click on last 3 Texts : WARNING: invoke for method [clickbutton()] failed
without case 2 (in file controller) it works well, I don't get any errors. so I think the problem is at nifty.gotoScreen("menu");
I had <screen id="menu" … in xml file, so I dont know what I did wrong.
Also all of effects dont work with my xml, I also dont know where could be the problem. might be the order in xml file? (<interact>-tag must be immediately after an element open tag)
or it doesnt work with text?
JMENifty06
import java.awt.event.KeyAdapter;
import com.jme3.app.SimpleApplication;
import com.jme3.input.KeyInput;
import com.jme3.input.binding.BindingListener;
import com.jme3.niftygui.NiftyJmeDisplay;
import de.lessvoid.nifty.Nifty;
public class JME3Nifty06 extends SimpleApplication implements BindingListener{
private Nifty nifty;
public static void main(String[] args){
JME3Nifty06 app = new JME3Nifty06();
app.setShowSettings(false);//disable config for start up
app.start();
}
@Override
public void simpleInitApp() {
Controller NiftyControl = new Controller();
//create nifty
NiftyJmeDisplay niftyDisplay = new NiftyJmeDisplay(assetManager,
inputManager,
audioRenderer,
guiViewPort);
nifty = niftyDisplay.getNifty();
nifty.fromXml("niftylabor/NewFile.xml","start",NiftyControl);
guiViewPort.addProcessor(niftyDisplay);
//this enble mouse cursor to show up
flyCam.setDragToRotate(true);
inputManager.setCursorVisible(true);
initKeys();
}
public void intputnifty() {
}
private void initKeys() {
inputManager.registerKeyBinding("start", KeyInput.KEY_SPACE);
inputManager.addBindingListener(this);
}
/** Custom Keybinding: Configure the action triggered by a binding */
public void onBinding(String binding, float value) {
}
@Override
public void onPostUpdate(float arg0) {
}
@Override
public void onPreUpdate(float arg0) {
}
}
XML file
<?xml version="1.0" encoding="UTF-8"?>
<nifty xmlns="http://nifty-gui.sourceforge.net/nifty.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://nifty-gui.sourceforge.net/nifty.xsd http://nifty-gui.sourceforge.net/nifty.xsd">
<screen id = "start" controller="niftylabor.Controller">
<layer align="center" backgroundColor="#1245" childLayout="center">
<panel childLayout="vertical" align="center" valign="center" visibleToMouse="true" >
<text text="Fight" color="#ffff" font="aurulent-sans-17.fnt" align="center">
<effect>
<onStartScreen mode="in" direction="left" startDelay="1000" length="2000" inherit="true"> </onStartScreen>
<onHover startDelay="0" length="500" post="true" startColor="#ffff" endColor="#0000" inherit="true"></onHover>
</effect>
</text>
<text text="Multi" color="#ffff" font="aurulent-sans-17.fnt" align="center"> <interact onClick="clickbutton()"/> </text>
<text text="Train" color="#fff2" font="aurulent-sans-17.fnt" align="center"> <interact onClick="clickbutton()"/> </text>
<text text="Exit" color="#fff5" font="aurulent-sans-17.fnt" align="center"> <interact onClick="clickbutton()"/> </text>
</panel>
</layer>
</screen>
<screen id = "menu" controller="niftylabor.Controller" >
<layer align="center" backgroundColor="#5600" >
<panel childLayout="vertical">
<text text="Resume" color="#0012" align="center"><interact onClick="clickbutton()"/> </text>
<text text="Option" color="#0012" align="center"><interact onClick="clickbutton()"/> </text>
<text text="Exit" color="#0012" align="center"><interact onClick="clickbutton()"/> </text>
</panel>
</layer>
</screen>
</nifty>
Controller
import de.lessvoid.nifty.Nifty;
import de.lessvoid.nifty.screen.Screen;
import de.lessvoid.nifty.screen.ScreenController;
/**
* ScreenController for Hello World Example.
* @author void
*/
public class Controller implements ScreenController {
public String test;
/** nifty instance. */
private Nifty nifty;
/**
* Bind this ScreenController to a screen.
* @param newNifty nifty
* @param newScreen screen
*/
public final void bind(final Nifty newNifty, final Screen newScreen) {
this.nifty = newNifty;
}
/**
* on start screen interactive.
*/
public final void onStartScreen() {
}
/**
* on end screen.
*/
public final void onEndScreen() {
}
/**
* quit method called from the niftygui04.xml.
*/
public final void clickbutton() {//create a trigger in the xml
System.out.println(nifty.getAllScreensName());
System.out.print("you click" + "n");//case1
nifty.gotoScreen("menu");//case2
}
}