Jump to content
  • Advertisement
Sign in to follow this  
EvilNando

How to handle game states ?

This topic is 3605 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

HI guys Im planning to implement something like a menu system that renders on top of the game area. My idea is that once you are inside the menu the game should be in another state so it knows how to handle input for the menu and also how to render itself. The problem Im having is that I cant figure how I can still render the game area because the way Im designing it , once you jump the game state the engine only can invoke the new's state Draw() method any help will be appreciated.

Share this post


Link to post
Share on other sites
Advertisement
When you switch states you might want to pass in the parent state (assuming a hierarchy) to the new one so that it can call the parent's Draw() method in its own Draw() if desired.

This thread may help if you're not sure how to implement a state system.

Share this post


Link to post
Share on other sites
Yeah a stack works really well:

StateManager
StateFunctions

Notice the Init, Process and Stop substates. These can be useful so a state knows when it begins and ends. You just push and pop states. So you can push a menu state over the game state and still have the game render and stuff if you want.
(I wrote that right when I first used C#, so there's better implementations).

Share this post


Link to post
Share on other sites
Will be a problem that instead of using stacks for remembering game states that each state has an Exit() function where it specifies to which state the game should go to?

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!