|
Size: 2486
Comment: Removed second category line.
|
← Revision 9 as of 2014-09-22 17:37:12 ⇥
Size: 2666
Comment: Fixed camel case links.,
|
| Deletions are marked like this. | Additions are marked like this. |
| Line 16: | Line 16: |
| SDL_Joystick joy = SDL_GameControllerGetJoystick(SDL_GameController* cont) | SDL_Joystick* SDL_GameControllerGetJoystick(SDL_GameController* gamecontroller) |
| Line 23: | Line 23: |
| ||'''SDL_GameController'''||The game controller object that you want to get a Joystick object from.|| | ||'''gamecontroller'''||the game controller object that you want to get a joystick from|| |
| Line 34: | Line 34: |
| #include <cstdio> //printf function . . . |
#include <stdio.h> /* for printf() */ /* ... */ |
| Line 38: | Line 40: |
| for(int i = 0; i < SDL_NumJoysticks(); i++) { if (SDL_IsGameController(i)) { printf("Index \'%i\' is a compatible controller, named \'%s\'\n", i, SDL_GameControllerNameForIndex(i)); ctrl = SDL_GameControllerOpen(i); joy = SDL_GameControllerGetJoystick(ctrl); } else { cout << "Index \'" << i << "\' is not a compatible controller." << endl; } |
int i; for(i = 0; i < SDL_NumJoysticks(); ++i) { if (SDL_IsGameController(i)) { printf("Index \'%i\' is a compatible controller, named \'%s\'\n", i, SDL_GameControllerNameForIndex(i)); ctrl = SDL_GameControllerOpen(i); joy = SDL_GameControllerGetJoystick(ctrl); } else { printf("Index \'%i\' is not a compatible controller.\n", i); } |
| Line 57: | Line 57: |
| This function will give you a SDL_Joystick object, which allows you to use the SDL_Joystick functions with a SDL_GameController object. This would be useful for getting a joystick's position at any given time, even if it hasn't moved (moving it would produce an event, which would have the axis' value). | This function will give you a SDL_Joystick object, which allows you to use the SDL_Joystick functions with a SDL_!GameController object. This would be useful for getting a joystick's position at any given time, even if it hasn't moved (moving it would produce an event, which would have the axis' value). |
| Line 61: | Line 61: |
| The pointer returned is owned by the SDL_!GameController. You should not call [[SDL_JoystickClose]]() on it, for example, since doing so will likely cause SDL to crash. |
DRAFT |
SDL_GameControllerGetJoystick
Use this function to get the Joystick ID from a Game Controller. The game controller builds on the Joystick API, but to be able to use the Joystick's functions with a gamepad, you need to use this first to get the joystick object.
Contents
Syntax
SDL_Joystick* SDL_GameControllerGetJoystick(SDL_GameController* gamecontroller)
Function Parameters
gamecontroller |
the game controller object that you want to get a joystick from |
Return Value
Returns a SDL_Joystick object; call SDL_GetError() for more information.
Code Examples
#include <stdio.h> /* for printf() */
/* ... */
SDL_GameController *ctrl;
SDL_Joystick *joy;
int i;
for(i = 0; i < SDL_NumJoysticks(); ++i) {
if (SDL_IsGameController(i)) {
printf("Index \'%i\' is a compatible controller, named \'%s\'\n", i, SDL_GameControllerNameForIndex(i));
ctrl = SDL_GameControllerOpen(i);
joy = SDL_GameControllerGetJoystick(ctrl);
} else {
printf("Index \'%i\' is not a compatible controller.\n", i);
}
}
Remarks
This function will give you a SDL_Joystick object, which allows you to use the SDL_Joystick functions with a SDL_GameController object. This would be useful for getting a joystick's position at any given time, even if it hasn't moved (moving it would produce an event, which would have the axis' value).
The pointer returned is owned by the SDL_GameController. You should not call SDL_JoystickClose() on it, for example, since doing so will likely cause SDL to crash.
