![]() |
Attention | Topic was automatically imported from the old Question2Answer platform. |
![]() |
Asked By | Ertain |
I’m trying to make an options screen that’s maneuverable by pressing the arrow keys (or by the directional pad on a controller).
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:
return
elif option_number < 0:
return
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)
else:
# 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)
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
rustyStriker | 2019-12-10 20:56
So there’s an option in the editor to keep track of whichControl
widgets after selected when the project is run?
Ertain | 2019-12-11 00:39
Indeed, it’s the focus_neighbour_...
settings on the node
rustyStriker | 2019-12-11 10:41
Easy to move selection menu in options menu with the help of null value reference.and input/ selection from keyboard and mouse.
assignmentservice | 2019-12-12 14:18