Wiki Page Content

Differences between revisions 1 and 8 (spanning 7 versions)
Revision 1 as of 2013-10-05 12:28:31
Size: 1883
Editor: Zalerinian
Comment:
Revision 8 as of 2016-04-10 22:30:07
Size: 1680
Comment: Replaced printf() with SDL_Log() in example.
Deletions are marked like this. Additions are marked like this.
Line 17: Line 17:
string map = SDL_GameControllerMapping(ctrl) char* SDL_GameControllerMapping(SDL_GameController* gamecontroller)
Line 22: Line 22:
||'''SDL_GameController'''||The game controller you want to get the current mapping for.|| ||'''gamecontroller'''||the game controller you want to get the current mapping for||
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 "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);
    }
Line 49: Line 51:
''You can add useful comments here''

##Leave this section as-is unless you have a remark to put in. In that case, replace ''You can add useful comments here'' with your remark(s) following the Style Guide instructions. Leave the rest of the markup alone and delete this comment.
The returned string must be freed with SDL_free().
Line 62: Line 62:
----
CategoryGameController

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 "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().


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