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 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:
- Have two game states: mainState, and gameState
- In the constructor for gameState, do all the initialization (loading models, creating lights, etc)
- 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.
- 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