Give access to the real-time state of the joysticks.
1 // Is joystick #0 connected? 2 bool connected = Joystick.isConnected(0); 3 * 4 // How many buttons does joystick #0 support? 5 uint buttons = Joystick.getButtonCount(0); 6 * 7 // Does joystick #0 define a X axis? 8 bool hasX = Joystick.hasAxis(0, Joystick.Axis.X); 9 * 10 // Is button #2 pressed on joystick #0? 11 bool pressed = Joystick.isButtonPressed(0, 2); 12 * 13 // What's the current position of the Y axis on joystick #0? 14 float position = Joystick.getAxisPosition(0, Joystick.Axis.Y);
*
$(KEYBOAD_LINK), $(MOUSE_LINK)
$(U Joystick) provides an interface to the state of the joysticks. It only contains static functions, so it's not meant to be instanciated. Instead, each joystick is identified by an index that is passed to the functions of this class. * This class allows users to query the state of joysticks at any time and directly, without having to deal with a window and its events. Compared to the JoystickMoved, JoystickButtonPressed, and JoystickButtonReleased events, $(U Joystick) can retrieve the state of axes and buttons of joysticks at any time (you don't need to store and update a boolean on your side in order to know if a button is pressed or released), and you always get the real state of joysticks, even if they are moved, pressed or released when your window is out of focus and no event is triggered. * DSFML supports:
* $(PARA Unlike the keyboard or mouse, the state of joysticks is sometimes not directly available (depending on the OS), therefore an `update()` function must be called in order to update the current state of joysticks. When you have a window with event handling, this is done automatically, you don't need to call anything. But if you have no window, or if you want to check joysticks state before creating one, you must call `Joystick.update` explicitly.) *