User Tools

Site Tools


en:tutorials:remapping_inputs

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
en:tutorials:remapping_inputs [2018/02/21 10:46 (7 months ago)]
sausage created
en:tutorials:remapping_inputs [2018/09/10 10:47 (8 days ago)] (current)
sausage
Line 13: Line 13:
   * ''​orxInput_Save'' ​   * ''​orxInput_Save'' ​
  
-The routine will allow the user to press any key or joystick button assigned to the ''​XButton''​ label in order to trigger a message to the console. They press the ''​Return''​ key to enter remap mode. Then pressing any joystick button will make the button the new one assigned to ''​XButton''​.+The routine will allow the user to press any key or joystick button assigned to the ''​XButton''​ label in order to trigger a message to the console. They press the ''​Enter''​ key to enter remap mode. Then pressing any joystick button will make the button the new one assigned to ''​XButton''​.
  
 Starting with the input config: Starting with the input config:
Line 20: Line 20:
 [MainInput] [MainInput]
 KEY_ESCAPE ​     = Quit KEY_ESCAPE ​     = Quit
-KEY_RETURN = Remap+KEY_ENTER = Remap
 JOY_12_1 = XButton ;Joystick binding JOY_12_1 = XButton ;Joystick binding
 KEY_X = XButton ;Keyboard alternative KEY_X = XButton ;Keyboard alternative
 </​code>​ </​code>​
  
-In the above config, the ''​Escape''​ key is used as the usual quit key and the ''​Return''​ key is the one used to put our game into "remap mode".+In the above config, the ''​Escape''​ key is used as the usual quit key and the ''​Enter''​ key is the one used to put our game into "remap mode".
  
 Then there are two controls mapped to ''​XButton'',​ ''​JOY_12_1''​ which is the 12th button on your joystick controller or gamepad, and secondly, the ''​X''​ key. Then there are two controls mapped to ''​XButton'',​ ''​JOY_12_1''​ which is the 12th button on your joystick controller or gamepad, and secondly, the ''​X''​ key.
Line 85: Line 85:
 First, if either ''​Joystick button 12''​ or the ''​X''​ key is pressed, a line is logged to the console. First, if either ''​Joystick button 12''​ or the ''​X''​ key is pressed, a line is logged to the console.
  
-Next, remap mode can be entered by pressing the ''​Return''​ key.+Next, remap mode can be entered by pressing the ''​Enter''​ key.
  
 In remap mode, ''​orxInput_GetActiveBinding''​ is constantly called. This will get the very last input that was made whether it be a key, a mouse movement, a joystick press, etc. Here, if it was a joystick press, store it for later, and it will be used as the button to remap to. In remap mode, ''​orxInput_GetActiveBinding''​ is constantly called. This will get the very last input that was made whether it be a key, a mouse movement, a joystick press, etc. Here, if it was a joystick press, store it for later, and it will be used as the button to remap to.
  
-''​orxInput_GetBindingList''​ is then called which returns the entire list of bindings. ​All bindings from each input are retrieved.+''​orxInput_GetBindingList''​ is then called which returns the entire list of bindings ​to ''​XButton''​There can be up to four physical inputs to a binding. ''​orxINPUT_KU32_BINDING_NUMBER''​ is a constant to 4.
  
-We then loop through the entire list looking for any joystick button type input and unbind ''​Xbutton''​ from them.+We then loop through the entire list looking for any joystick button type input and unbind ''​XButton''​ from them.
  
-''​orxInput_Bind''​ is then called using the joystick button that was saved at the start using '​orxInput_GetActiveBinding''​. This is bound to ''​XButton''​.+''​orxInput_Bind''​ is then called using the joystick button that was saved at the start using ''​orxInput_GetActiveBinding''​. This is bound to ''​XButton''​.
  
 Finally, ''​orxInput_Save''​ is called to save the new input config section to a new file. This can then be loaded whenever your game is started. Finally, ''​orxInput_Save''​ is called to save the new input config section to a new file. This can then be loaded whenever your game is started.
  
 Finally remap mode is turned off, and if you press the new joystick button that you chose, it will start to log to console instead of the previous joystick button. Finally remap mode is turned off, and if you press the new joystick button that you chose, it will start to log to console instead of the previous joystick button.
 +
 +
 +<WRAP center round tip 90%>
 +**Note:** when using ''​orxInput_GetActiveBinding'',​ it only collects an input for the specific frame. A slow custom clock will miss values especially if they are fast inputs like mouse wheel clicks. Therefore, it is recommended that the **core clock** is used. See [[en:​tutorials:​testing_input_controls|here]] for an example.
 +</​WRAP>​
en/tutorials/remapping_inputs.1519209993.txt.gz ยท Last modified: 2018/02/21 10:46 (7 months ago) by sausage