Hi
In the code below if i uncomment lines 11 to 18 then my program starts working correctly,
i.e if i press ButtonA on my gamepad I can exit.
But when those lines are commented like they are right now, then gamepad doesn’t work.
why is that?
thanks in advance.
-
#include <SDL2/SDL.h>
-
#include “stdio.h”
-
int main()
-
{
-
SDL_Init(SDL_INIT_GAMECONTROLLER);
-
SDL_Window *Window = SDL_CreateWindow("Hello SDL", 50, 50, 500, 500, 0);
-
if (SDL_IsGameController(0) == SDL_TRUE) {
-
SDL_GameController *Controller = SDL_GameControllerOpen(0);
-
while (1) {
-
/*
-
SDL_Event *Event = NULL;
-
SDL_PollEvent(Event);
-
while (Event != NULL) {
-
if (Event->type == SDL_QUIT) {
-
return 0;
-
}
-
SDL_PollEvent(Event);
-
}
-
*/
-
int ButtonA = SDL_GameControllerGetButton(Controller, SDL_CONTROLLER_BUTTON_A);
-
int ButtonB = SDL_GameControllerGetButton(Controller, SDL_CONTROLLER_BUTTON_B);
-
if (ButtonA == 1) {
-
break;
-
}
-
if (ButtonB == 1) {
-
printf("ButtonB is Down\n");
-
}
-
}
-
}
-
else {
-
printf("the joystick is not a game controller\n");
-
}
-
}