joysticks.gd 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. extends Node2D
  2. # Joysticks demo, written by Dana Olson <[email protected]>
  3. #
  4. # This is a demo of joystick support, and doubles as a testing application
  5. # inspired by and similar to jstest-gtk.
  6. #
  7. # Licensed under the MIT license
  8. var joy_num
  9. var cur_joy
  10. var axis_value
  11. var btn_state
  12. func _ready():
  13. set_process_input(true)
  14. func _input(ev):
  15. # get the joystick device number from the spinbox
  16. joy_num = get_node("joy_num").get_value()
  17. # display the name of the joystick if we haven't already
  18. if joy_num != cur_joy:
  19. cur_joy = joy_num
  20. get_node("joy_name").set_text( Input.get_joy_name(joy_num) )
  21. # loop through the axes and show their current values
  22. for axis in range(0,8):
  23. axis_value = Input.get_joy_axis(joy_num,axis)
  24. get_node("axis_prog"+str(axis)).set_value(100*axis_value)
  25. get_node("axis_val"+str(axis)).set_text(str(axis_value))
  26. # loop through the buttons and highlight the ones that are pressed
  27. for btn in range(0,17):
  28. btn_state = 1
  29. if (Input.is_joy_button_pressed(joy_num, btn)):
  30. get_node("btn"+str(btn)).add_color_override("font_color",Color(1,1,1,1))
  31. else:
  32. get_node("btn"+str(btn)).add_color_override("font_color",Color(0.2,0.1,0.3,1))