Wiki Page Content

Differences between revisions 1 and 3 (spanning 2 versions)
Revision 1 as of 2013-10-05 04:59:57
Size: 2545
Editor: Zalerinian
Comment:
Revision 3 as of 2013-10-05 15:58:32
Size: 2486
Comment: Removed second category line.
Deletions are marked like this. Additions are marked like this.
Line 7: Line 7:
= SDL_Function = = SDL_GameControllerGetJoystick =
Line 64: Line 64:
----
CategoryGameController CategoryGameController CategoryGameController

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.

Syntax

SDL_Joystick joy =  SDL_GameControllerGetJoystick(SDL_GameController* cont)

Function Parameters

SDL_GameController

The game controller object that you want to get a Joystick object from.

Return Value

Returns a SDL_Joystick object; call SDL_GetError() for more information.

Code Examples

#include <cstdio> //printf function
. . .
SDL_GameController *ctrl;
SDL_Joystick *joy;
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;
  }
}

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


CategoryAPI, CategoryGameController

None: SDL_GameControllerGetJoystick (last edited 2014-09-22 17:37:12 by PhilippWiesemann)

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