Game States - game loop

Started by
1 comment, last by ghosted 18 years, 8 months ago
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.
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.
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

This topic is closed to new replies.

Advertisement