jme3 nifty: gotoscreen how?


The codes are almost the same from the end of this link

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?


import java.awt.event.KeyAdapter;
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
       public void simpleInitApp() {
          Controller NiftyControl = new Controller();
          //create nifty
          NiftyJmeDisplay niftyDisplay = new NiftyJmeDisplay(assetManager,
          nifty = niftyDisplay.getNifty();
          //this enble mouse cursor to show up
       public void intputnifty() {
       private void initKeys() {
           inputManager.registerKeyBinding("start", KeyInput.KEY_SPACE);
       /** Custom Keybinding: Configure the action triggered by a binding */
       public void onBinding(String binding, float value) {

      public void onPostUpdate(float arg0) {

      public void onPreUpdate(float arg0) {

XML file

<?xml version="1.0" encoding="UTF-8"?>
<nifty xmlns="" xmlns:xsi="" xsi:schemaLocation="">

<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">
   <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>

<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>

<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>



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.print("you click" + "n");//case1


There was a time when Nifty always created that warning that a method invoke has failed when it actually executed it without problems. what Nifty version do you use? the latest from svn should be correct without that warning. is the method always called and you only wonder about that message? I couldn't follow your description exactly when you have what error. Can you send an example where the method invoke fails and skip everything else?

About your effects: Well, they miss the name='which-effect-do-you-want-to-use' attribute :slight_smile:

<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>

I think you need to add an name="move" to your onStartScreen effect and name="fade" to your onHover effect maybe.

thank you very much creator,

I managed to solve the problem with your help

I dont know which version of nifty I am using, I just know it is the nifty in jme3 nightly build from yesterday (now it is already today ^^ ) thought it works like I want now it still gives out the warning: WARNING: invoke for method [clickbutton()] failed

the problems were

  • Well, they miss the name='which-effect-do-you-want-to-use' attribute  - like you said ^^

  • the menu screen had so much similar colors, so even it changed i didnt see anything (my mistake ^^ )

      and in xml file I didnt have the font attribute in menu screen  font="aurulent-sans-17.fnt"

    that was ^^

    may be you should make a default font, so if user forget to define the font they wont get problem.

    also where can I see which fonts nifty supports ? or can I add new fonts to nifty ?

great that it works now! congratz! :slight_smile:

I think there might be an older nightly build of nifty included in jme3 so I’d not worry too much about the warning. I suppose the warning will go away with nifty 1.2 :slight_smile:

Nifty supports bitmap based fonts in the angelcode font format. You can see this response from me for details;topicseen#msg103700


I think that warning will go away soon,too.

the fonts are somewhat complicated for me, so I think it will take me quite a while to prepare the next questions, in the meanwhile I will try to attack effects and other parts of nifty first ^^

I have a lot of idea I want to try now, it would be great that I were a monster with 3 heads and 6 hands