Size: 1702
Comment: Added SDL_Init() in example.
|
Size: 1680
Comment: Replaced printf() with SDL_Log() in example.
|
Deletions are marked like this. | Additions are marked like this. |
Line 30: | Line 30: |
#include <stdio.h> /* for printf() */ | #include "SDL.h" |
Line 41: | Line 41: |
printf("Index \'%i\' is a compatible controller, named \'%s\'\n", i, SDL_GameControllerNameForIndex(i)); | SDL_Log("Index \'%i\' is a compatible controller, named \'%s\'", i, SDL_GameControllerNameForIndex(i)); |
Line 43: | Line 43: |
printf("Controller %i is mapped as \"%s\".\n", i, SDL_GameControllerMapping(ctrl)); | SDL_Log("Controller %i is mapped as \"%s\".", i, SDL_GameControllerMapping(ctrl)); |
Line 45: | Line 45: |
printf("Index \'%i\' is not a compatible controller.", i); | SDL_Log("Index \'%i\' is not a compatible controller.", i); |
DRAFT |
SDL_GameControllerMapping
Use this function to get the current mapping of a Game Controller.
Contents
Syntax
char* SDL_GameControllerMapping(SDL_GameController* gamecontroller)
Function Parameters
gamecontroller |
the game controller you want to get the current mapping for |
Return Value
Returns a string that has the controller's mapping. More information about the mapping can be found on SDL_GameControllerAddMapping; call SDL_GetError() for more information.
Code Examples
#include "SDL.h"
/* ... */
SDL_GameController *ctrl;
int i;
SDL_Init(SDL_INIT_GAMECONTROLLER);
for (i = 0; i < SDL_NumJoysticks(); ++i) {
if (SDL_IsGameController(i)) {
SDL_Log("Index \'%i\' is a compatible controller, named \'%s\'", i, SDL_GameControllerNameForIndex(i));
ctrl = SDL_GameControllerOpen(i);
SDL_Log("Controller %i is mapped as \"%s\".", i, SDL_GameControllerMapping(ctrl));
} else {
SDL_Log("Index \'%i\' is not a compatible controller.", i);
}
}
Remarks
The returned string must be freed with SDL_free().