Joystick demo script cleanup

Removes a leftover variable and uses constants instead of magic numbers.
This commit is contained in:
Andreas Haas 2016-05-10 20:32:12 +02:00
parent bc31be9812
commit 86b46c0b7e
1 changed files with 4 additions and 5 deletions

View File

@ -12,7 +12,6 @@ extends Node2D
var joy_num var joy_num
var cur_joy var cur_joy
var axis_value var axis_value
var btn_state
const DEADZONE = 0.2 const DEADZONE = 0.2
@ -26,11 +25,12 @@ func _fixed_process(delta):
get_node("joy_name").set_text(Input.get_joy_name(joy_num)) get_node("joy_name").set_text(Input.get_joy_name(joy_num))
# Loop through the axes and show their current values # Loop through the axes and show their current values
for axis in range(0, 8): for axis in range(JOY_ANALOG_0_X, JOY_AXIS_MAX):
axis_value = Input.get_joy_axis(joy_num, axis) axis_value = Input.get_joy_axis(joy_num, axis)
get_node("axis_prog" + str(axis)).set_value(100*axis_value) get_node("axis_prog" + str(axis)).set_value(100*axis_value)
get_node("axis_val" + str(axis)).set_text(str(axis_value)) get_node("axis_val" + str(axis)).set_text(str(axis_value))
if (axis < 4): # Show joystick direction indicators
if (axis <= JOY_ANALOG_1_Y):
if (abs(axis_value) < DEADZONE): if (abs(axis_value) < DEADZONE):
get_node("diagram/axes/" + str(axis) + "+").hide() get_node("diagram/axes/" + str(axis) + "+").hide()
get_node("diagram/axes/" + str(axis) + "-").hide() get_node("diagram/axes/" + str(axis) + "-").hide()
@ -40,8 +40,7 @@ func _fixed_process(delta):
get_node("diagram/axes/" + str(axis) + "-").show() get_node("diagram/axes/" + str(axis) + "-").show()
# Loop through the buttons and highlight the ones that are pressed # Loop through the buttons and highlight the ones that are pressed
for btn in range(0, 16): for btn in range(JOY_BUTTON_0, JOY_BUTTON_MAX):
btn_state = 1
if (Input.is_joy_button_pressed(joy_num, btn)): 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("btn" + str(btn)).add_color_override("font_color", Color(1, 1, 1, 1))
get_node("diagram/buttons/" + str(btn)).show() get_node("diagram/buttons/" + str(btn)).show()