diff options
author | punto- <ariel@godotengine.org> | 2016-01-06 06:41:44 -0300 |
---|---|---|
committer | punto- <ariel@godotengine.org> | 2016-01-06 06:41:44 -0300 |
commit | 5464ab53887f905d67c0d7c74bf1fcf46f3fe96c (patch) | |
tree | ec7e05eb66a69ff32c9de88582af92c51d41c650 /demos/misc/joysticks/joysticks.gd | |
parent | bf6429e9aca86acafd790cd2fb77bf31c009bb44 (diff) | |
parent | 63ad92f4c20db7c24d7cc56831da0cd81769003c (diff) |
Merge pull request #3251 from Hinsbart/joy_demo
update joystick demo with visual representation
Diffstat (limited to 'demos/misc/joysticks/joysticks.gd')
-rw-r--r-- | demos/misc/joysticks/joysticks.gd | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/demos/misc/joysticks/joysticks.gd b/demos/misc/joysticks/joysticks.gd index 7add88573d..f5bc1bddad 100644 --- a/demos/misc/joysticks/joysticks.gd +++ b/demos/misc/joysticks/joysticks.gd @@ -14,8 +14,9 @@ var cur_joy var axis_value var btn_state +const DEADZONE = 0.2 -func _input(event): +func _fixed_process(delta): # Get the joystick device number from the spinbox joy_num = get_node("joy_num").get_value() @@ -29,15 +30,24 @@ func _input(event): axis_value = Input.get_joy_axis(joy_num, axis) get_node("axis_prog" + str(axis)).set_value(100*axis_value) get_node("axis_val" + str(axis)).set_text(str(axis_value)) + if (axis < 4): + if (abs(axis_value) < DEADZONE): + get_node("diagram/axes/" + str(axis) + "+").hide() + get_node("diagram/axes/" + str(axis) + "-").hide() + elif (axis_value > 0): + get_node("diagram/axes/" + str(axis) + "+").show() + else: + get_node("diagram/axes/" + str(axis) + "-").show() # Loop through the buttons and highlight the ones that are pressed - for btn in range(0, 17): + for btn in range(0, 16): btn_state = 1 if (Input.is_joy_button_pressed(joy_num, btn)): get_node("btn" + str(btn)).add_color_override("font_color", Color(1, 1, 1, 1)) + get_node("diagram/buttons/" + str(btn)).show() else: get_node("btn" + str(btn)).add_color_override("font_color", Color(0.2, 0.1, 0.3, 1)) - + get_node("diagram/buttons/" + str(btn)).hide() func _ready(): - set_process_input(true) + set_fixed_process(true) |