I’m trying to use the Gamecontroller api and can’t get it to work
Just from the test code below
if (SDL_NumJoysticks() > 0) {
printf("%d\n",SDL_NumJoysticks());
joy = SDL_JoystickOpen(0);
if (joy) {
if(SDL_IsGameController(0)){
printf("Is game controller\n");
controller = SDL_GameControllerOpen(0);
char *mapping;
mapping = SDL_GameControllerMapping(controller);
printf("Controller mapped as \n%s\n",mapping);
SDL_GameControllerEventState(SDL_ENABLE);
}
printf("Opened Joystick 0\n");
printf("Name: %s\n", SDL_JoystickNameForIndex(0));
printf("Number of Axes: %d\n", SDL_JoystickNumAxes(joy));
printf("Number of Buttons: %d\n", SDL_JoystickNumButtons(joy));
printf("Number of Balls: %d\n", SDL_JoystickNumBalls(joy));
} else {
printf("Couldn't open Joystick 0\n");
}
}
SDL is initialiazed with SDL_INIT_JOYSTICK, the test seems detect my controller and mapping just fine, but when I use:
while(SDL_PollEvent(&event)){
switch(event.type){
...
case SDL_CONTROLLERBUTTONDOWN:
printf("test\n");
}
}
I can never make it print anything, it seems that the event is never generated.
What am I doing wrong?