Em đã thử theo cách người ta bày như sau
bool init() {
//Initialize what we need
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_JOYSTICK) < 0) {
printf("SDL could not initialized! Error: %s\n", SDL_GetError());
return false;
}
.........
.........
.........
SDL_JoystickEventState(SDL_ENABLE);
//Check for joystick subsystem
if (SDL_NumJoysticks() <= 0) { // <<<<<<< get stuck in here
printf("Warning: No joysticks connected\n");
}
else {
//Load joysticks subsystem
controller = SDL_JoystickOpen(0);
if (controller == NULL) {
printf("Warning: Unable to open game controller! Error: %s\n", SDL_GetError());
return false;
}
}
.......
.......
.......
return true;
}
Khi chạy đến phần kiểm tra số lượng joystick khởi tạo được
if (SDL_NumJoysticks() <= 0) {
printf("Warning: No joysticks connected\n");
}
thì nhận được thông báo “No joysticks connected”.
Vậy có nghĩa là Joystick subsystem vẫn được khởi tạo nhưng không tạo ra đc joystick nào.
Em nên khởi tạo thế nào cho đúng?