Je suis lazy foo's tutorial, mais je me suis rendu compte chaque fois que j'appuie sur s
ou p
, SDL_KEYDOWN
deux fois. Comment cela peut-il être réparé?SDL_KEYDOWN déclenchement deux fois
Voici l'extrait de code:
while(SDL_PollEvent(&e) != 0) {
if(e.type == SDL_QUIT) {
quit = true;
}
else if(e.type == SDL_KEYDOWN) {
if(e.key.keysym.sym == SDLK_s) {
if(timer.isStarted()) {
timer.stop();
printf("stop\n");
}
else {
timer.start();
printf("start\n");
}
}
else if(e.key.keysym.sym == SDLK_p) {
if(timer.isPaused()) {
timer.unpause();
printf("unpause\n");
}
else {
timer.pause();
printf("pause\n");
}
}
}
}
En appuyant sur s
fois:
start
stop