Let’s say I have 3 AppStates: Main Menu/ Pause Menu/ Highscore Menu
in Simpleinitapp I switched to Main Menu, and I made buttons in Main Menu, so my question is how to switch from Main Menu to Play Menu or High scores menu once I click on a button?
Actually I have never used AppstateManager a lot before, but I needed it lately, I have thought of something like that:
first I make a package called Variables.
I make a new class called global variables and I do like:
int CurrentAppState = 1; // which means main menu
boolean SwitchedToMainMenu = true;
boolean SwitchedToGameMenu = false;
then when I click on a button for example play button:
Variables.globalvariables.CurrentAppState = 2; // which means game Menu
and after that in the update on Main.java:
if(Variables.globalvariables.SwitchedToGameMenu == false && Variables.globalvariables.CurrentAppState == 2) {
Variables.globalvariables.SwitchedToGameMenu = true;
Variables.globalvariables.SwitchedToMainMenu = false;
//then after that detach the MainMenu appstate and attach the Game Appstate
}
Will it work like that? I mean would it be buggy or something? or is there a better solution?
Just keep a list of your AppStates when you create them? You seem to fall into the trap of wanting a library to do what your application is supposed to do.
So let’s say I have 3 appstates Main Menu State/ Game Menu State/Pause Menu State
Now when the application starts I switch to Main Menu State , and Inside Main Menu State I created the buttons which is : play and quit , so when a player click on play , I want to disable Main Menu State and enable the other one, so how can I disable it
Personally, I’m having trouble figuring out where your confusion is.
You can see how I use app states here:
Essentially, app states are a way to temporarily “extend” the application’s functionality. As such they are useful for lots of things… “screen management” is just one small thing.
That’s why I suggested looking at the javadocs for AppStateManager as it would have shown you how to grab an existing state, etc… If you don’t know how to pull up javadocs then you really should find out.