Game Development Reference
In-Depth Information
count the focus of the window. So imagine that a player minimizes the window and
browses the internet. The function will still return true if the player presses the given
key.
With this in mind, the given code can be very easily reworked to something much more
pleasant:
As you can see, we don't need to store any key state in this case—SFML does that for us.
We can check the states of other input devices in a similar way. The mouse has functions
to get its position, the state of any of its buttons, as well as the setting of its position relat-
ive to the desktop (not any of the windows). To get the position, you can use
Mouse::getPosition() . To set the position, you can use
Mouse::setPosition() . Finally, to check whether a button is pressed, call
Mouse::isButtonPressed() . All of these work out of focus as well.
Finally, there are joysticks. Since all functions are static, we need to specify which joy-
stick we are looking for with its argument Id . The functions are as follows:
Function
Arguments Description
This function checks whether the joystick with the given ID is
connected
Joystick::isConnected()
ID
ID, axis
This function checks whether the joystick has the specified axis
Joystick::hasAxis()
Joystick::getButtonCount() ID
This function gets the number of buttons on the joystick
Joystick::getAxisPosition() ID, axis
This function gets the value of an axis in the range [0, 1]
Search WWH ::




Custom Search