SDL_SetJoystickVirtualAxis(3)

πŸ’– SDL_SetJoystickVirtualAxis(3) πŸ’–

okay bestie so we're in the SDL3 FUNCTIONS section of the manual, and today's main character is SDL_SetJoystickVirtualAxis β€” the girl who sets axis state on a virtual joystick you already opened. no cap.


✨ NAME ✨

SDL_SetJoystickVirtualAxis β€” Set the state of an axis on an opened virtual joystick.

like, you made a fake controller, and now you're telling one of its sticks/triggers what to do. iconic behavior.


πŸŽ€ SYNOPSIS πŸŽ€

#include <SDL3/SDL_joystick.h>

bool SDL_SetJoystickVirtualAxis(SDL_Joystick *joystick, int axis, Sint16 value);

🌸 DESCRIPTION 🌸

okay so listen, this is the part you cannot skip, fr fr:

Please note that values set here will not be applied until the next call to SDL_UpdateJoysticks. 🫢

and that SDL_UpdateJoysticks call can either be called directly, or it can be called indirectly through various other SDL APIs, including, but not limited to, the following:

  • SDL_PollEvent
  • SDL_PumpEvents
  • SDL_WaitEventTimeout
  • SDL_WaitEvent

so basically you're setting a vibe and then waiting for the pipeline to actually vibe-check it. the way that nothing happens until you pump those events… lowkey the whole game.

also, huge heads up for the trigger girlies: when sending trigger axes, you should scale the value to the full range of Sint16. for example, a trigger at rest would have the value of SDL_JOYSTICK_AXIS_MIN. periodt. don't come crying to me when your trigger is resting at the wrong number πŸ’…


πŸ¦‹ FUNCTION PARAMETERS πŸ¦‹

  • joystick β€” the virtual joystick on which to set state. it's the one you opened, bestie, the chosen one πŸ‘‘
  • axis β€” the index of the axis on the virtual joystick to update. yes, index, it's a number, count carefully πŸ“
  • value β€” the new value for the specified axis. a Sint16, so bring the whole range ✨

πŸ’… RETURN VALUE πŸ’…

Returns true on success or false on failure. and if it's giving failure, call SDL_GetError() for more information β€” she will tell you exactly what went wrong, she's never shy 😭


🧚 THREAD SAFETY 🧚

It is safe to call this function from any thread. any thread! not me being fully portable and emotionally available from every thread at once 🌈


⭐ AVAILABILITY ⭐

This function is available since SDL 3.2.0. so if you're on something older, no axis for you, sorry babe πŸ™ˆ


πŸ”₯ SEE ALSO πŸ”₯

the whole virtual joystick friend group, go say hi:


and that's the page, bestie πŸ’œ this one's brought to you by Simple Directmedia Layer, manual version SDL 3.4.18 β€” mwah, stay slaying, and remember: nothing applies until you update those joysticks πŸŽ€βœ¨

πŸ“¦ where this page comes from