So, I'm trying to learn how to use joysticks with SDL2, and I'm following LazyFoo's Tutorial(Gamepads and Joysticks), but I must've been doing something wrong because my program won't detect my controller!
Windows detects it(I'm using Windos 7 and a wireless Xbox 360 controller) and LazyFoo's example(which I downloaded from the link above) also detects my controller!
I searched and tried some things, but nothing that I tried seems to work...
Here's my Init:
if (SDL_Init(SDL_INIT_EVERYTHING) < 0){
cout << "Error initializing SDL!" << endl;
return 1;
}
And this part is inside the constructor of my Input class, whic was supposed to "start" the joystick(and also detects event from the keyborad):
if (SDL_NumJoysticks() < 1){
cout << "No joystick detected." << endl;
}
else{
controller = SDL_JoystickOpen(0);
if (controller == NULL){
cout << "Error: Unable to open Joystick." << endl;
}
else{
isUsingJoystick = true;
}
}
I also tried using SDL_JoystickEventState(SDL_ENABLE)
after the Init and SDL_JoystickUpdate()
, but it did'nt worked either...
What am I forgetting?
If you guys want, I can edit the post with the codes of my Input class...
EDIT: I forgot to say that, even though my controller is connected and everything, SDL_NumJoysticks()
returns 0...