Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Basic Joystick Help Needed  (Read 2080 times)

0 Members and 1 Guest are viewing this topic.

Druidpeter

  • Newbie
  • *
  • Posts: 7
    • View Profile
    • Email
Basic Joystick Help Needed
« on: February 22, 2019, 02:56:21 pm »
I want to start adding Joystick functionality to my game, but I have no experience with Joysticks, and the documentation is confusing on some points.

1. Does "Joystick" refer only to an analog stick, or does it refer to multiple types of non keyboard mouse controller objects?

2. I'm having a hard time understanding the Axis part of the documentation. The documentation says that SFML supports 8 axes, and lists X,Y,Z,R,U,V,POV X, POVY. Are all of these Axes components of a single analog stick? How do I use them to basically read analog stick movement and translate that into, say, player movement on screen? Are these Axes part of different analog sticks? Do some of them go unused?

3. The controllers basically just enumerate buttons from 0-31. How do you figure out if a certain button maps to, say, the Xbox 360 'A' button, for example?

Sorry for the trouble, and thank you for your time.

Arcade

  • Full Member
  • ***
  • Posts: 230
    • View Profile
Re: Basic Joystick Help Needed
« Reply #1 on: February 22, 2019, 04:13:09 pm »
Several of these questions could be quickly cleared up by just giving it a try (assuming you own a joystick or gamepad of course  :) )

1.  The latter. "Joystick" is being used as a generic term for several types of devices, including the Xbox 360 controller you mention.

2. No they are not necessarily components of a single analog stick. As you can probably imagine, there are many types of joysticks/gamepads with various numbers of analog controls. Depending on your controller, yes some of them may go unused.

For example, the Xbox 360 controller has 2 analog sticks. Moving one of them left would probably correspond to a negative X axis value. Right might be positive X. Up might be positive Y. The other stick might use U and V instead of X and Y. The 2 "triggers" on the controller might also be considered analog, so might correspond to the negative and positive values of the Z axis.

3. There is no easy way to do this because the mappings are determined by the joystick's driver. Each joystick driver can assign logical buttons and axis numbers to whatever physical button or axis they want. Again, you can probably imagine many joysticks or gamepads that look quite different, so it would be hard for there to be a single standard for this. You will just need to test your particular gamepad and figure out what the mappings are. If you want to support more gamepads, the "simple" thing to do would be to allow the user to remap the controls themselves in a settings menu. Alternatively or you can get information about their joystick via sf::joystick::getIdentification() and try to incorporate a database in your game that already has the mappings for common brands of joystick.

Druidpeter

  • Newbie
  • *
  • Posts: 7
    • View Profile
    • Email
Re: Basic Joystick Help Needed
« Reply #2 on: February 28, 2019, 03:33:53 pm »
Ah! All right. Thank you very much, Arcade. Sorry for all the trouble. :D