sdlGetJoystickAxis function

int sdlGetJoystickAxis(
  1. Pointer<SdlJoystick> joystick,
  2. int axis
)

Get the current state of an axis control on a joystick.

SDL makes no promises about what part of the joystick any given axis refers to. Your game should have some sort of configuration UI to let users specify what each axis should be bound to. Alternately, SDL's higher-level Game Controller API makes a great effort to apply order to this lower-level interface, so you know that a specific axis is the "left thumb stick," etc.

The value returned by SDL_GetJoystickAxis() is a signed integer (-32768 to 32767) representing the current position of the axis. It may be necessary to impose certain tolerances on these values to account for jitter.

\param joystick an SDL_Joystick structure containing joystick information. \param axis the axis to query; the axis indices start at index 0. \returns a 16-bit signed integer representing the current position of the axis or 0 on failure; call SDL_GetError() for more information.

\since This function is available since SDL 3.1.3.

\sa SDL_GetNumJoystickAxes

extern SDL_DECLSPEC Sint16 SDLCALL SDL_GetJoystickAxis(SDL_Joystick *joystick, int axis)

Implementation

int sdlGetJoystickAxis(Pointer<SdlJoystick> joystick, int axis) {
  final sdlGetJoystickAxisLookupFunction = libSdl3.lookupFunction<
      Int16 Function(Pointer<SdlJoystick> joystick, Int32 axis),
      int Function(
          Pointer<SdlJoystick> joystick, int axis)>('SDL_GetJoystickAxis');
  return sdlGetJoystickAxisLookupFunction(joystick, axis);
}