deadlychicken22
Man is a reasoning rather than a reasonable animal
The code for my menu loop and a couple other loops of mine seems to have some problems with them. When I test them on my gp2x and I don't press any button for awhile, it will freeze up on me and not react to any buttons. However, my input loop in my game loop seems to work fine (no freezing). I have looked through both of them many times and can't find the problem. The code for my main menu is below, please help me find the source of my problems.
Thanks,
-ben
Code:
int option=1;
int selectOption=0;
//variables for button input
int exit_menu = 0;
//MENU LOOP HERE
while(exit_menu == 0)
{
SDL_Event event;
while(SDL_PollEvent(&event))
{
switch(event.type)
{
case SDL_JOYBUTTONDOWN:
switch(event.jbutton.button)
{
case GP2X_BUTTON_UP:
option -= 1;
break;
case GP2X_BUTTON_DOWN:
option += 1;
break;
break;
case GP2X_BUTTON_X:
selectOption = 1;
break;
}
break;
}
}
//act on input
if(selectOption == 1)
{
selectOption = 0;
//if the user selects story mode
if(option == 1) exit_menu = 1;
//if the user selects arcade mode
else if(option == 2) exit_menu = 1;
else if(option == 3)
{
//If the user exits
chdir("/usr/gp2x");
execl("/usr/gp2x/gp2xmenu", "/usr/gp2x/gp2xmenu", NULL);
return 0;
}
}
if(option < 1) option=3;
if(option > 3) option=1;
//-----Draw menu
menu = load_image("menu_background.bmp");
//Draw menu options
if(option == 1) options_screen = load_image("option1.bmp");
if(option == 2) options_screen = load_image("option2.bmp");
if(option == 3) options_screen = load_image("option3.bmp");
DrawIMG(menu, screen, 0, 0);
DrawIMG(options_screen, screen, 132, 142);
//Blit image to actual screen
SDL_Flip(screen);
}
//End Menu Loop
Thanks,
-ben