소스 검색

Update docs to show how to use JoystickConnectionListener (#95)

* Update docs to show how to use JoystickConnectionListener

* Update docs to show how to use JoystickConnectionListener

* Add for joystick connection state link to input handling
James Khan 6 년 전
부모
커밋
f5641e5757
2개의 변경된 파일27개의 추가작업 그리고 0개의 파일을 삭제
  1. 4 0
      src/docs/asciidoc/jme3/advanced/input_handling.adoc
  2. 23 0
      src/docs/asciidoc/jme3/beginner/hello_input_system.adoc

+ 4 - 0
src/docs/asciidoc/jme3/advanced/input_handling.adoc

@@ -330,3 +330,7 @@ private AnalogListener analogListener = new AnalogListener() {
 It is likely that your players have different keyboard layouts, are used to “reversed mouse navigation, or prefer different navigational keys than the ones that you defined. You should create an options screen that lets users customize their mouse/key triggers for your mappings. Replace the trigger literals in the `inputManager.addMapping()` lines with variables, and load sets of triggers when the game starts. 
 
 The abstraction of separating triggers and mappings has the advantage that you can remap triggers easily. Your code only needs to remove and add some trigger mappings. The core of the code (the listeners and actions) remains unchanged. 
+
+== Detecting Joystick Connection States
+
+For information regarding the connection state of a joystick see <<jme3/beginner/hello_input_system.adoc#listening-for-joystick-connections, Listening for Joystick Connections>>.

+ 23 - 0
src/docs/asciidoc/jme3/beginner/hello_input_system.adoc

@@ -333,6 +333,29 @@ KeyTrigger(KeyInput.KEY_RIGHT)
 If you don't recall an input constant during development, you benefit from an IDE's code completion functionality: Place the caret after e.g. `KeyInput.|` and trigger code completion to select possible input identifiers.
 ====
 
+== Listening For Joystick Connections
+
+Note: Joystick Connection/Disconnection events are only available in *LWJGL3*.
+
+If your game requires handling the addition and removal of new joystick devices you can subscribe to a joystick connection listener.
+This will give you the opportunity to enable joystick movement, pause the game if the joystick is disconnected, change keybindings to mouse/keyboard.
+
+[source, java]
+----
+inputManager.addJoystickConnectionListener(new JoystickConnectionListener() {
+            @Override
+            public void onConnected(Joystick joystick) {
+                System.out.println("Joystick connected: " + joystick.getName());
+            }
+
+            @Override
+            public void onDisconnected(Joystick joystick) {
+                System.out.println("Joystick Disconnected: " + joystick.getName());
+            }
+        });
+----
+
+
 == Exercises
 
 .  Add mappings for moving the player (box) up and down with the H and L keys!