+1 vote

I'm trying to make an options screen that's maneuverable by pressing the arrow keys (or by the directional pad on a controller).

Options screen

I have tried putting in code to allow for this form of navigation. When the user presses down a few times, the "Credits" option is the only thing highlighted, even though the player should be able to control which option is highlighted. I don't know why it won't highlight another option when the player presses up or down.

The following is the code for the options screen:

extends Control

# Which option is selected?
var option_number: int = 0
var shadow_color: String = "2dea12"

# Nodes to reference
onready var x_sensitivity: Label = $"VBoxContainer/HBoxContainer/X-sensitivity"
onready var y_sensitivity: Label = $"VBoxContainer/HBoxContainer2/Y-sensitivity"
onready var test_play: Label = $VBoxContainer/Test_play
onready var credits: Label = $VBoxContainer/Credits

# Collect all the options into an array for handy reference.
var list_of_options: Array = []

func _ready():
    list_of_options = [
    x_sensitivity, y_sensitivity, test_play, credits

# Depending upon whether the player presses up or down on the directional pad, increment or decrement the "option_number" variable.
func _input(event):
    if event.is_action_pressed("ui_down"):
        option_number = clamp( option_number + 1.0, 0.0, list_of_options.size() - 1 )
    if event.is_action_pressed("ui_up"):
        option_number = clamp( option_number - 1.0, 0.0, list_of_options.size() - 1 )

func _process(change_in_frame):
    if option_number > list_of_options.size() - 1:
    elif option_number < 0:
    for option in [0,1,2,3]:
        if option == option_number:
            # Make the option letters look highlighted.
            list_of_options[option_number].add_color_override( "font_color_shadow", Color(shadow_color) )
            list_of_options[option_number].add_constant_override("shadow_as_outline", 2)
            # Make the option letters look plain.
            list_of_options[option_number].add_color_override("font_color_shadow", ColorN("black") )
            list_of_options[option_number].add_constant_override("shadow_as_outline", 0)
in Engine by (1,979 points)

Didnt really dove deep into your code, more of a side note, the Control scenes have the option to set which Control node will be at where when you press the directions

So there's an option in the editor to keep track of whichControl widgets after selected when the project is run?

Indeed, it's the focus_neighbour_... settings on the node

Easy to move selection menu in options menu with the help of null value reference.and input/ selection from keyboard and mouse.

1 Answer

0 votes
Best answer

rustyStriker told me about the focus_neightbour_[...] properties in the editor. I was able to assign the focus_neighbour_top and focus_neighbour_bottom properties to the nodes I want highlighted. KBraven in the Godot Discord channel clued me into setting the focus_modes of the Labels (I set them to "All"). So now I can use the "ui_up" and "ui_down" keys to select the options.

by (1,979 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.