   Overlapping Game States
  HiOkey here is my problem... To keep my game code as organized as possible I have several game states. Like:Developer IntroGame IntroMain menuMain Gameetc.The system is like this, a function called SetState takes an init a release and a run function then it run the current release function (if any) then the init function.My problem is sometimes I want to make effects between states which requires resources from both states now things starts to get complicated. I dont want to release a lot of stuff and then load it and probably cause a little latency.My question is, how do people solve this kind of problems. Maybe my State system is that good, what should a perfect state system look like?My quesions may sound a little diffuse, tell me if Ive to clearify something.thanks   
  The approach I use is to have a stack of gamestates, inspired by this article:Managing Game States in C++ .Works really well for me with small adjustments. The user can start a gameStack: PlayGameStatepress escape to get back to the menuStack: MenuGameState PlayGameStateThen maybe look at the highscoresStack: HighscoresGameState MenuGameState PlayGameStatethen go all the way back to the PlayGameState like nothing had happend (in code by popping the top-most gamestates)The GameStateManager::update() method calls update() on the top-most gamestate, so that only the "visible" game state gets updated, and the state of the other game states are preserved.   ;  Really interesting, thanks! the link you gave me talked about my main problem with overlapping effects but didnt really handle it I think. When some of the resources are used in the beginning of the effect and depening on which state it comes from. with push/pop it feels like a waste to have everything "behind".   ;Quote:Original post by ProblemBabyReally interesting, thanks! the link you gave me talked about my main problem with overlapping effects but didnt really handle it I think. When some of the resources are used in the beginning of the effect and depening on which state it comes from. with push/pop it feels like a waste to have everything "behind".Personally I use a game state manager along with an Enginuity Kernel. Using these together alllows me to solve a very broad spectrum of problems (that being said, the game I am building on top of the engine is not overly complex).Concerning the leaving-everything-behind; you could make a game state free its resources when (using the same terminology as in the article) its CGameState::Pause() method gets called. Then the game state could reallocate its resources in its CGameState::Resume() method. This would ofcourse create a probably noticable delay when changing between states, but that's the price you'll have to pay if you want as much resources as free as possible. Maybe you could make some connection with a resource manager so the resources for a game state was only free:ed when there is a resource shortage.In any case, the article is more like a hint (at least it was for me). It takes a while to get it to work right, but that's the fun part of it [smile].   ;  Couldn't you just implement what the article says and just add in some ways for the states to communicate with other states on the stack.. that way you could have the topmost member gamestate call the previous member's updatetransition function or something.   ;  For a transition between states, have a new type of state called Transition which has references to the 'before' and 'after' states. Its own rendering method does the appropriate mix of the two states, and when it is done it removes itself from the state queue and replaces itself with the 'after' state.   ;  That's kind of what i do too. When i create a new state, it gets a pointer to the old state in case it wants to save anything. Then the old state is deleted and the new state properly set up in it's place.   