Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Game Loop?

This topic is 5545 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

Could someone give me an example of games main loop... where the logig is updated and thing drawn. How do join it with state based game logic.
GameMain()
{
  switch (GameState)
  GS_MENU: MenuLoop;
  GS_MAIN: GameLoop;
  GS_IDLE: IdleLoop;
}

MenuLoop()
{
  UpdateMenu;
  DrawMenu;
}

GameLoop()
{
  UpdateGameLogic();
  DrawStuff();
}

IdleLoop()
{
  PlayDemo();
}
 
this is how currently have thought doing it. How you do it? Pekka H http://koti.mbnet.fi/pekkath/

Share this post


Link to post
Share on other sites
Advertisement
You can also create an abstract GameState base class and then derive states like PlayState and EditState from it and override the Draw and Process functions, so in effect each frame involves a virtual function call.

Share this post


Link to post
Share on other sites
Looks fine, just make sure that the MenuLoop, GameLoop etc have their own while loop inside, rather than a while loop in GameMain. Although im sure that is how you done it.

Share this post


Link to post
Share on other sites

  • 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!