crabs-game/scripts/ControlIndicator.gd

42 lines
1011 B
GDScript3
Raw Permalink Normal View History

2020-08-20 14:45:54 +02:00
extends AnimatedSprite
const press_a = preload("res://images/Controls/PressA.tres")
const press_space = preload("res://images/Controls/PressSpace.tres")
const press_down = preload("res://images/Controls/PressDown.tres")
const press_left = preload("res://images/Controls/PressLeft.tres")
const press_up = preload("res://images/Controls/PressUp.tres")
const press_right = preload("res://images/Controls/PressRight.tres")
var last_is_joy = false
func show_press(action : String):
if action == 'ui_accept':
frames = press_a if last_is_joy else press_space
if action == 'right':
frames = press_right
if action == 'left':
frames = press_left
if action == 'down':
frames = press_down
if action == 'up':
frames = press_up
play('default')
show()
func _input(event):
last_is_joy = false
for b in [
JOY_XBOX_A,
JOY_XBOX_B,
JOY_XBOX_X,
JOY_XBOX_Y,
JOY_DPAD_UP,
JOY_DPAD_LEFT,
JOY_DPAD_RIGHT,
JOY_DPAD_DOWN,
]:
if Input.is_joy_button_pressed(-1, b):
last_is_joy = true
break