GUI Gamestate

I've been working on a GUI however i'm definitly no were near completed but i've been working off of the example from New Integrating FengGUI with jME - by Unfair however i'm using gamestates. I usually create a seperate class and then in the same class create a public static class however i've been having slight issues attaching the rootnode to attachChild i'm unsure of what i should return in the class i do know i have to call a spatial but not sure how i should go about it.

here is the portion of the code before i attempted to create the gamestate from also i want to impliment a single boolean i can call in order to change a couple values around however i could properly figure that out. Can anyone assist

   FengJMEInputHandler input;

   org.fenggui.Display disp; // FengGUI's display
      // Create the GUI
      disp = new org.fenggui.Display(new org.fenggui.binding.render.lwjgl.LWJGLBinding());
      input = new FengJMEInputHandler(disp);
      //LabelExample GUI = new LabelExample();
      initGUI(disp, false);
 ///////////////////////////////////////////////////////////////GUI STARTS////////////////////////////////////
    * Create our GUI.  FengGUI init code goes in here
    *@param Display display, boolean GameStarted(adds functionality and scaling if game started)
   protected void initGUI(Display display, boolean GameStarted)
      // Grab a display using an LWJGL binding
      //      (obviously, since jME uses LWJGL)      
      input = new FengJMEInputHandler(disp);
      //Initialize the window      
      final Container mainMenuContainer = new Container();
      mainMenuContainer.getAppearance().add(new PlainBackground(Color.RED));
      //mainMenuContainer.getAppearance().setPadding(new Spacing(90, 90));
      mainMenuContainer.setLayoutManager(new RowLayout(true));
      //Initialize the menu and set up appearences
      Menu mainMenu = new Menu();
      //random colors to see what each one does
      //Initialize menu components
      mainMenu.addItem(gameMenu(disp, "Game"));
      //Shows end game Menu if game is active
      if (GameStarted!=false)   {mainMenu.addItem(endGameMenu(disp,"End Game"));}      
      mainMenu.addItem(endProgram(disp,"End Program"));
   // Update the display with the newly added components
   private MenuItem gameMenu(final Display d, final String s){
      MenuItem gameItem = new MenuItem(s);
      //Initialzie GameWindow
      gameItem.addMenuItemPressedListener(new IMenuItemPressedListener(){
         public void menuItemPressed(MenuItemPressedEvent menuItemPressedEvent)
            //Sets up the Window
            Window mainMenu = FengGUI.createWindow(d, false, false, false, true);      
            mainMenu.setPosition(new Point(d.getWidth()/2,d.getHeight()/2));
            mainMenu.setLayoutManager(new RowLayout(false));
            //Sets up the Menu
            Menu gameMenu = new Menu();
            MenuItem Continue = new MenuItem("Continue");
            MenuItem newGame = new MenuItem("New game");
            gameMenu.getAppearance().add(new PlainBackground(Color.WHITE_HALF_TRANSPARENT));
            //Attach the Menu to the window
            // Update the display with the newly added components
      return gameItem;
   private MenuItem multiplayerMenu(Display d, String s){
      MenuItem multiplayerMenu = new MenuItem(s);
      return multiplayerMenu;
   private MenuItem optionsMenu(Display d, String s){
      MenuItem optionsMenu = new MenuItem(s);
      // need to figure a way to set up a container
      return optionsMenu;
   private MenuItem endGameMenu(Display d, String s){
      MenuItem endGameMenu = new MenuItem(s);
      return endGameMenu;
   private MenuItem endProgram(final Display d, final String s){
      MenuItem endProgram = new MenuItem(s);
      //initializes End Program Window;
      endProgram.addMenuItemPressedListener(new IMenuItemPressedListener(){
      public void menuItemPressed(MenuItemPressedEvent menuItemPressedEvent)
            //remember to change how this exits when implimented
         try {
            gameWindow(d, s);
         } catch (InterruptedException e) {
            // TODO Auto-generated catch block
      return endProgram;
   private Window gameWindow(Display d, String s)throws java.lang.InterruptedException {
      //Sets up the Window
      Window mainMenu = FengGUI.createWindow(disp, false, false, false, true);      
      mainMenu.setPosition(new Point(disp.getWidth()/2,disp.getHeight()/2));
      mainMenu.setLayoutManager(new RowLayout(false));
      //Sets up the exit Label
      Label endProgramLabel = FengGUI.createLabel("Program will end in ");
      //initialize count down
      CountDown endGameCounter = new CountDown(15, mainMenu);
      Label second = FengGUI.createLabel(Float.toString(endGameCounter.countDownValue));
      //Attach the Label to the window
      // Update the display with the newly added components
      return mainMenu;
   class CountDown extends Controller {

       private float elapsedTime = 0.0f;
       private float totalTime;
       private Container fengContainer;
       private Widget lastLabel = null;

       public CountDown(float totalTime, Container fengContainer) {

           this.totalTime = totalTime;
           this.fengContainer = fengContainer;

       public  float countDownValue = totalTime - elapsedTime;
       public void update(float tpf) {

           elapsedTime += tpf;

          if(countDownValue < 0.0f)
               countDownValue = 0.0f;
          // Ideally you would update update the text of the label instead of creating a new one as done below.
          // Without code in front of me I couldn't do it for you, but I know you can.

           if(lastLabel != null)

           lastLabel = FengGUI.createLabel(Integer.toString((int)countDownValue));

           if(countDownValue == 0.0f)

   ////////////////////////////////////////////////////GUI ENDS//
   I have added FengGui game state to my project and it works fine, but renders under the other game state. I have tried adding the FengGui gamestate first and last, and it doesn't matter?

   It doesn't render 'after' because you need to flush the queue, call Renderer.renderQueue(), after the first pass finishes. If you have an InGameState and a GUIGameState, you need to put the statement after all your code in the InGameState render method:


   You need to flush the queue at the end of your IngameGameState render method. The FengGUI GameState needs to be added after the IngameGameState. If this doesn't work, try clearing the Zbuffer after rendering (in IngameGameState.render) with Renderer.clearZBuffer, then it SHOULD work if the GameStates are rendered in the correct order.

There is an example using FengGUI / Gamestates and RenderPasses

This wiki entry has two main classes, one is using only gamestates, and one is using RenderPasses warpped in Gamestates.

Only with RenderPasses you can get FengGUI to dislplay properly.

thx core-dump the renderpass fixed another problem i was having as well thx

In the example given there is only one GameState beside the FengGUI GameState.

What if I use more GameStates. Would this work? Has anyone done this?

Thanks for every info.