Browse Source

Update input event to 3.0

Max Hilbrunner 7 years ago
parent
commit
7ccdf3b022
1 changed files with 25 additions and 15 deletions
  1. 25 15
      tutorials/inputs/inputevent.rst

+ 25 - 15
tutorials/inputs/inputevent.rst

@@ -9,9 +9,32 @@ What is it?
 Managing input is usually complex, no matter the OS or platform. To ease
 Managing input is usually complex, no matter the OS or platform. To ease
 this a little, a special built-in type is provided, :ref:`InputEvent <class_InputEvent>`.
 this a little, a special built-in type is provided, :ref:`InputEvent <class_InputEvent>`.
 This datatype can be configured to contain several types of input
 This datatype can be configured to contain several types of input
-events. Input Events travel through the engine and can be received in
+events. Input events travel through the engine and can be received in
 multiple locations, depending on the purpose.
 multiple locations, depending on the purpose.
 
 
+Here is a quick example, closing your game if the escape key is hit:
+
+::
+
+    func _unhandled_input(event):
+        if event is InputEventKey:
+            if event.pressed and event.scancode == KEY_ESCAPE:
+                get_tree().quit()
+
+However, it is cleaner and more flexible to use the provided :ref:`InputMap <class_InputMap>` feature,
+which allows you to define input actions and assign them different keys. This way,
+you can define multiple keys for the same action (e.g. they keyboard escape key and the start button on a gamepad).
+You can then more easily change this mapping in the project settings without updating your code,
+and even build a key mapping feature on top of it to allow your game to change the key mapping at runtime!
+
+You can setup your InputMap under **Project > Project Settings > Input Map** and then use those actions like this:
+
+::
+
+    func _process(delta):
+        if Input.is_action_pressed("ui_right"):
+            # Move right
+
 How does it work?
 How does it work?
 -----------------
 -----------------
 
 
@@ -67,20 +90,7 @@ Anatomy of an InputEvent
 anything and only contains some basic information, such as event ID
 anything and only contains some basic information, such as event ID
 (which is increased for each event), device index, etc.
 (which is increased for each event), device index, etc.
 
 
-InputEvent has a "type" member. By assigning it, it can become
-different types of input event. Every type of InputEvent has different
-properties, according to its role.
-
-Example of changing event type.
-
-::
-
-    # create event
-    var ev = InputEventMouseButton.new()
-    # button_index is only available for the above type
-    ev.button_index = BUTTON_LEFT
-
-There are several types of InputEvent, described in the table below:
+There are several specialised types of InputEvent, described in the table below:
 
 
 +-------------------------------------------------------------------+--------------------+-----------------------------------------+
 +-------------------------------------------------------------------+--------------------+-----------------------------------------+
 | Event                                                             | Type Index         | Description                             |
 | Event                                                             | Type Index         | Description                             |