43 lines
1.6 KiB
GDScript
43 lines
1.6 KiB
GDScript
extends VBoxContainer
|
|
|
|
export var joypad_index = 0
|
|
|
|
# Called when the node enters the scene tree for the first time.
|
|
func _ready() -> void:
|
|
pass # Replace with function body.
|
|
|
|
const color_off = Color.blue
|
|
const color_on = Color.white
|
|
|
|
var id_left = 0
|
|
var id_down = 1
|
|
var id_up = 2
|
|
var id_right = 3
|
|
var id_start = 4
|
|
var id_back = 5
|
|
|
|
func set_name(name):
|
|
$Label.text = name
|
|
|
|
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
|
func _process(delta: float) -> void:
|
|
var left = Input.get_joy_axis(joypad_index, id_left)
|
|
var down = Input.get_joy_axis(joypad_index, id_down)
|
|
var up = Input.get_joy_axis(joypad_index, id_up)
|
|
var right = Input.get_joy_axis(joypad_index, id_right)
|
|
var start = Input.get_joy_axis(joypad_index, id_start)
|
|
var back = Input.get_joy_axis(joypad_index, id_back)
|
|
$Grid/left/Label.text = "%.03f" % left
|
|
$Grid/down/Label.text = "%.03f" % down
|
|
$Grid/up/Label.text = "%.03f" % up
|
|
$Grid/right/Label.text = "%.03f" % right
|
|
$TopRow/lbl_start.text = "start\n%.03f" % start
|
|
$TopRow/lbl_back.text = "back\n%.03f" % back
|
|
|
|
$Grid/left/t.modulate = color_on if Input.is_joy_button_pressed(joypad_index, id_left) else color_off
|
|
$Grid/down/t.modulate = color_on if Input.is_joy_button_pressed(joypad_index, id_down) else color_off
|
|
$Grid/up/t.modulate = color_on if Input.is_joy_button_pressed(joypad_index, id_up) else color_off
|
|
$Grid/right/t.modulate = color_on if Input.is_joy_button_pressed(joypad_index, id_right) else color_off
|
|
$TopRow/lbl_start.uppercase = Input.is_joy_button_pressed(joypad_index, id_start)
|
|
$TopRow/lbl_back.uppercase = Input.is_joy_button_pressed(joypad_index, id_back)
|