2014-08-06 06:29:14 +00:00
|
|
|
|
|
|
|
extends Node2D
|
|
|
|
|
|
|
|
# Joysticks demo, written by Dana Olson <dana@shineuponthee.com>
|
|
|
|
#
|
|
|
|
# This is a demo of joystick support, and doubles as a testing application
|
|
|
|
# inspired by and similar to jstest-gtk.
|
|
|
|
#
|
|
|
|
# Licensed under the MIT license
|
|
|
|
|
2015-11-21 12:31:25 +00:00
|
|
|
# Member variables
|
2014-08-06 06:29:14 +00:00
|
|
|
var joy_num
|
|
|
|
var cur_joy
|
|
|
|
var axis_value
|
|
|
|
var btn_state
|
|
|
|
|
|
|
|
|
2015-12-09 07:38:23 +00:00
|
|
|
func _input(event):
|
2015-11-21 12:31:25 +00:00
|
|
|
# Get the joystick device number from the spinbox
|
2014-08-06 06:29:14 +00:00
|
|
|
joy_num = get_node("joy_num").get_value()
|
2015-12-09 07:38:23 +00:00
|
|
|
|
2015-11-21 12:31:25 +00:00
|
|
|
# Display the name of the joystick if we haven't already
|
2014-08-06 06:29:14 +00:00
|
|
|
if joy_num != cur_joy:
|
|
|
|
cur_joy = joy_num
|
2015-12-09 07:38:23 +00:00
|
|
|
get_node("joy_name").set_text(Input.get_joy_name(joy_num))
|
|
|
|
|
2015-11-21 12:31:25 +00:00
|
|
|
# Loop through the axes and show their current values
|
2015-12-09 07:38:23 +00:00
|
|
|
for axis in range(0, 8):
|
|
|
|
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))
|
|
|
|
|
2015-11-21 12:31:25 +00:00
|
|
|
# Loop through the buttons and highlight the ones that are pressed
|
2015-12-09 07:38:23 +00:00
|
|
|
for btn in range(0, 17):
|
2014-08-06 06:29:14 +00:00
|
|
|
btn_state = 1
|
|
|
|
if (Input.is_joy_button_pressed(joy_num, btn)):
|
2015-12-09 07:38:23 +00:00
|
|
|
get_node("btn" + str(btn)).add_color_override("font_color", Color(1, 1, 1, 1))
|
2014-08-06 06:29:14 +00:00
|
|
|
else:
|
2015-12-09 07:38:23 +00:00
|
|
|
get_node("btn" + str(btn)).add_color_override("font_color", Color(0.2, 0.1, 0.3, 1))
|
|
|
|
|
|
|
|
|
|
|
|
func _ready():
|
|
|
|
set_process_input(true)
|