I have a code:
Code:
SDL_Event event;
while(continue){
/*full instructions*/
quitOrEsc(&continue, event);
}
With the function quitOrEsc:
Code:
/*Procedure: verified if the ESC key is pressed or if it was an event SDL_QUIT (v)
without blocking the execution of the program
Data: Address varible loop and variable of the event.
EB: zero of the variable if either event is detected.
Preconditions: have initialized SDL
*/
void quitOrEsc(int *continue, SDL_Event event)
{
SDL_PollEvent(&event);
switch(event.type){
case SDL_QUIT:
*continue = 0;
break;
case SDL_KEYDOWN:
switch (event.key.keysym.sym){
case SDLK_ESCAPE:
*continue = 0;
break;
default:
break;
}
break;
default:
break;
}
}
Unfortunately I'm pressing the escape key or clicking on the cross but still it won't leave it, do you know why? How will the program come to know whether I have clicked any key or button?
Bookmarks