Jump to content
  • Advertisement
Sign in to follow this  
PennstateLion

Game States - game loop

This topic is 4839 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, I am thinking about handling my game states as a base class with the specific game states (Game, Menu, Exit, Pause, etc...). inheriting from the base class. Each specific game state will have member functions that handle rendering, input, etc... In my Game Gamestate i plan on having the game loop as a member function. So my winmain will make a call to the Game ojbect and the memberfunction of gameloop. I was looking for advice whether the main game loop that is called from winmain should be a member function of an object. Is there any downfalls to this..? Right now as it stands, my main game loop is just a c type function that is called from winmain.

Share this post


Link to post
Share on other sites
Advertisement
I don't have too much experience with this, but the game loop is a core function that you only want one instance of. With my game, I use it as a base level. It's really just sends the amount of time transpired to the objects in the game since the last loop so they can update themselves and then calls a draw for each object on the level.

Share this post


Link to post
Share on other sites
I have operated with the same system and experienced no problems so far. With a base CGamestate class that all my game states inherit from I simply ensure each one has an overridden update(), draw() and various input functions. Everygame loop my main will use a pointer to my current gamestate and update it then draw it. Swapping the gamestate is simply a matter of reassigning the pointer.

I'm actually considering developing it further and maintaining another pointer for the previous gamestate, this will allow me to do silly effects when I swap between states like a fade or wipe.

There are no problems with the main loop coming directly from the WinMain. I actually have a class between the WinMain and the Gamestates called CEngine but thats for added functionality and if you're not needing such a class then leaving things where they are for now is just fine. It can easily be moved at a later date if need be.

HTH

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!