From 42565d3d289e521dd3da3bd6e3ea013ec6cf5b1a Mon Sep 17 00:00:00 2001 From: reduz Date: Sun, 2 Nov 2014 19:05:30 -0800 Subject: [PATCH] Updated tutorial_input_events (markdown) --- tutorial_input_events.md | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/tutorial_input_events.md b/tutorial_input_events.md index e543335..0be82c8 100644 --- a/tutorial_input_events.md +++ b/tutorial_input_events.md @@ -27,7 +27,7 @@ Example of changing event type. ```python # create event -var ev = InputEvent.new() +var ev = InputEvent() # set type index ev.type=InputEvent.MOUSE_BUTTON # button_index is only available for the above type @@ -49,10 +49,28 @@ There are several types of InputEvent, described in the table below: |[InputEventAction](class_inputeventaction)|SCREEN_ACTION|Contains a generic action. These events are often generated by the programmer as feedback. (more on this below)| +### Actions + +An InputEvent may or may not represent a pre-defined action. Actions are useful because they abstract the input device when programming the game logic. This allows for: + +* The same code to work on different devices with different inputs (ie: keyboard on PC, Joypad on console) +* Input to be reconfigured at run-time. + +Actions can be created from the Project Settings menu in the Actions tab. If you read the [2D Game Tutorial](tutorial_2d), there is an explanation on how does the action editor work. + +Any event has the methods [InputEvent.is_action()](class_inputevent#is_action), [InputEvent.is_pressed()](class_inputevent#is_pressed) amd [InputEvent.is_echo()](class_inputevent#is_echo). + +Alternatively, it may be desired to supply the game back with an action from the game code (a good example of this is detecting gestures). SceneTree (derived from MainLoop) has a method for this: [MainLoop.input_event(ev)](class_mainloop#input_event). You would normally use it like this: + +```python +var ev = InputEvent() +ev.type=InputEvent.ACTION +#set as move_left, pressed +ev.set_as_action("move_left",true) +#feedback +get_tree().input_event(ev) +``` +### InputMap - --explain input event --explain input editor --explain as actions -explain InputMap and how to map to user-events. \ No newline at end of file