-
Notifications
You must be signed in to change notification settings - Fork 0
/
Sprite.gd
43 lines (38 loc) · 1.01 KB
/
Sprite.gd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
extends Sprite
var positions = []
var index = 0
func _ready():
for node in get_parent().get_children():
if node is Label and node.visible:
print(node.name, node.rect_position.x)
positions.append(node)
set_selection(0)
func set_selection(new_index):
if new_index >= 0 and new_index < len(positions):
index = new_index
var selected_node = positions[index]
position = Vector2(
selected_node.rect_position.x - (get_rect().size.x * scale.x) / 2 - 10,
selected_node.rect_position.y + selected_node.rect_size.y/2
)
else:
print("Error")
func _process(delta):
var action = positions[index]
if Input.is_action_just_pressed("ui_up"):
if index == 0:
$sound.play()
set_selection(len(positions) - 1)
else:
$sound.play()
set_selection(index - 1)
if Input.is_action_just_pressed("ui_down"):
if index == len(positions) - 1:
$sound.play()
set_selection(0)
else:
$sound.play()
set_selection(index + 1)
if Input.is_action_just_pressed("ui_accept"):
$sound.play()
action.callback()