SDL_EventState toggle
I've been using SDL_EventState as to disable and enable certain events. However for some reason once I set any state to either on or off, no where else in the program can I chang开发者_StackOverflow中文版e it. To explain further, here is my loop.
void game::startLoop()
{
while(QUIT == false)
{
getRoomUpdate();
applySurface(-15, 280, zombie_lefthand, buffer);
applySurface(455, 280, zombie_righthand, buffer);
SDL_Flip(buffer);
SDL_WaitEvent(&gameEvent);
{
switch(gameEvent.type)
{
case SDL_QUIT:
QUIT = true;
break;
case SDL_KEYUP:
switch(gameEvent.key.keysym.sym)
{
case SDLK_LEFT:
if(isTwoWay == true)
SDL_EventState(SDL_KEYUP, 1);
startLoop();
log("Left key pressed.");
SDL_EventState(SDL_KEYUP, 0);
case SDLK_RIGHT:
if(isTwoWay == true)
SDL_EventState(SDL_KEYUP, 1);
startLoop();
log("Right key pressed.");
SDL_EventState(SDL_KEYUP, 0);
case SDLK_UP:
if(isTwoWay == false)
SDL_EventState(SDL_KEYUP, 1);
startLoop();
log("Up key pressed.");
SDL_EventState(SDL_KEYUP, 0);
default:
SDL_EventState(SDL_KEYUP, 0);
}
}
}
}
}
Perhaps if you tried someone else's code.
If it worked you could try to transform their code to something like yours(functionally wise)
Good Luck!
p.s. I think you should use SDL_ENABLE and SDL_DISABLE.
精彩评论