Sign in to follow this  
Chad Smith

(SDL)Main Menu Problem

Recommended Posts

Chad Smith    1343
Ok, I am creating a game for my History Project. The project is due tommorow, and I have been working non-stop for a week, to get this project done. You can say that I have been in crunch mode. Anyway, today I fixed a collision detection issue, so that fixed 3 bugs at the same time. So I go..."YES", but I was wrong. I go to make the Main Menu, and guess what...for some reason it is not working! I would just figure this out by my self, but I only have the rest of tonight to fix this problem, so I had to come here and ask. Here is the problem: The Main Menu flips properly, and it accepts input, but after it accepts the input, it just closes! I have tried all kinds of different techniques to fix this, but none of them have worked. Can y'all help me please? Code:
void Main_Menu()
{
       SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER  );
       TTF_Init();
       SDL_SetVideoMode( WINDOW_WIDTH, WINDOW_HEIGHT, 0, SDL_DOUBLEBUF );
       SDL_WM_SetCaption(WINDOW_TITLE, 0);
       SDL_Event event;
       
       while(menurunning)
       {
             printf("Now in the Main Menu");
             DrawText("(P)lay Game", 24, WINDOW_WIDTH/2, WINDOW_HEIGHT/2, 255, 255, 255, 0, 0, 0);
             DrawText("(I)nformation About Game", 24, WINDOW_WIDTH/2, WINDOW_HEIGHT/2+30, 255, 255, 255, 0, 0, 0); 
             DrawText("(E)xit Game", 24, WINDOW_WIDTH/2, WINDOW_HEIGHT/2+60, 255, 255, 255, 0, 0, 0);
             while(SDL_PollEvent(&event))
             {
                  if(event.type==SDL_QUIT)
                  {
                       gamerunning=false;
                  }
               
            }
             if(event.type==SDL_KEYDOWN)
             {
                  switch(event.key.keysym.sym)
                  {
                       case SDLK_p: Init_Game(); break;
                       case SDLK_i: Information(); break;
                       case SDLK_e: SDL_Quit(); break;
                  }
             }
             SDL_Flip(SDL_GetVideoSurface());
       }
}

Thanks to all who help! Chad.

Share this post


Link to post
Share on other sites
Luctus    584
SDL_PollEvent only returns 0 when the event queue is empty, so it will continue looping until the queue is empty. Then the if block only checks wheter the event that was last fetched into the event variable is a SDL_KEYDOWN event. So unless the SDL_KEYDOWN event you're waiting for aren't last in the queue when you enter that while block, nothing will happen.

Could of course be a number of other things too..

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this