![]() |
Attention | Topic was automatically imported from the old Question2Answer platform. |
![]() |
Asked By | Maximm |
So I’ve been working on a menu system for selecting levels in my game controlled with WASD. (As in you use WASD to navigate through the menu to find the level you want to play)
Just a little bit of an explanation of the system I have in place; I have a Vector2 variable that changes depending on what button you press, then each level has a Vector2 value assigned to themselves.
My point is that the way of detecting the player’s input doesn’t seem very optimized and I wanted to see if anybody could help improve it somehow.
Actual detection: (It runs in the _input() function)
func change_selected_minigame_pos():
if Input.is_action_just_pressed("right"):
selected_minigame_pos.x += 1
if Input.is_action_just_pressed("left"):
selected_minigame_pos.x -= 1
if Input.is_action_just_pressed("down"):
selected_minigame_pos.y += 1
if Input.is_action_just_pressed("up"):
selected_minigame_pos.y -= 1
Other things that could potentially be useful:
func _process(delta):
if Input.is_action_just_pressed("space"):
print(selected_minigame.minigame_data.minigame_description)
limit_movement()
for i in minigame_container.get_children():
if i is MinigamePromptComponent:
if selected_minigame_pos == i.prompt_position:
i.select()
selected_minigame = i
else:
i.deselect()
This looks fine, really. But you could try using the built-in focus system if you are using any Control-derived nodes for the menu, which would not even require coding the selection inputs you made. Check this out:
Keyboard/Controller Navigation and Focus — Godot Engine (stable) documentation in English
Ox0zOwra | 2023-06-07 22:56