Change won't show

Hey,

I tried making my own Menu for my little game and almost everythink works.



I just got only little problem.

When i press "Start Game" in the Menu i do the following:

menuState.getRootNode().detachAllChildren();
menuState.setActive(false);
gameState.setActive(true);
menu.main.startNewGame();



menuState is the gameState with the Menu, so first i try to delete all the Nodes from the rootNode, so that i get a blank screen.

menu.main.startNewGame() does all the initialization, for example i load all the models, create the lights and so on.

But wenn i press Start Game the objects from the rootNode everythink actually gets deleted, but it's still displayed.
Then it takes a few seconds to load the game and then it switches to the game.
But when i go back to the menu all the objects are deleted, so the objects get deleted, but the display won't update.

What do i have to do so the display updates before loading all the objects and models?

I don't understand the relationship between gameState and menu.main, but here's what I suggest:

  1. Have two game states: mainState, and gameState
  2. In the constructor for gameState, do all the initialization (loading models, creating lights, etc)
  3. When you press "Start Game", get rid of the first and fourth lines in your sample code.



    By setting the menuState to not be active, those objects will be not displayed.  When you set the gameState to active, those objects will be displayed.  The way you're doing it now, I suspect that the objects in menuState are being deleted like you expect, but the reason they still display is because the models, lights, etc are being created.  When you go back to the menu, you're not seeing any updated display because you detached all the children when you switched to gameState!  Also, unless you're setting the gameState to not be active, it's objects will still be displayed, even while you're displaying the menuState.



    Make sense?



    Summarized:
  • create the objects you want to display in the constructor of each gameState
  • use setActive(true) to display the objects of a state, and setActive(false) to hide them



    Good luck.