Wiki Page Content

Differences between revisions 4 and 5
Revision 4 as of 2013-10-05 16:24:26
Size: 1871
Comment: Corrected parameter name and description, see SGFunctions page.
Revision 5 as of 2013-10-13 11:43:42
Size: 1897
Comment: Fixed syntax errors in C++ example and changed it to C.
Deletions are marked like this. Additions are marked like this.
Line 30: Line 30:
#include <cstdio> // the printf function
. . .

SDL_GameController *ctrl
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);
    printf("Controller %i is mapped as \"%s\".\n", i, SDL_GameControllerMapping(ctrl);
}
  else
 
{
    printf("Index \'%i\' is not a compatible controller.", i);
  }
#include <stdio.h> /* for printf() */

/* ... */

SDL_GameController *ctrl;
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);
        printf("Controller %i is mapped as \"%s\".\n", i, SDL_GameControllerMapping(ctrl));
  
} else {
        printf("Index \'%i\' is not a compatible controller.", i);
    }

DRAFT

SDL_GameControllerMapping

Use this function to get the current mapping of a Game Controller.

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 <stdio.h> /* for printf() */

/* ... */

SDL_GameController *ctrl;
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);
        printf("Controller %i is mapped as \"%s\".\n", i, SDL_GameControllerMapping(ctrl));
    } else {
        printf("Index \'%i\' is not a compatible controller.", i);
    }
}

Remarks

You can add useful comments here


CategoryAPI, CategoryGameController

None: SDL_GameControllerMapping (last edited 2016-04-10 22:39:25 by PhilippWiesemann)

Feedback
Please include your contact information if you'd like to receive a reply.
Submit