I have a menu controller node that is a CanvasLayer node, and I have a canvas layer and multiple menu nodes below the menu controller node.
The following control code handles toggling between the regular game mode and opening the game menu and pause screen:
(:Edit: There is a variable, "isInMenu" that is set to false initially on scene load. Thank you. :3 )
func _process(delta):
if Input.is_action_just_pressed("game_menu") and isInMenu == true:
# Exit game menu.
for child in children:
child.visible = false
child.set_process(false)
player.set_process(true)
isInMenu = false
var tmp = ""
if Input.is_action_just_pressed("pause_game"):
tmp = "PauseMenu"
elif Input.is_action_just_pressed("game_menu") and isInMenu == false:
tmp = "GameMenu"
isInMenu = true
for child in children:
if child.get_name() == tmp:
child.visible = true
child.set_process(true)
else:
child.visible = false
child.set_process(false)
if tmp == "PauseMenu":
pause_game()
elif tmp == "GameMenu":
player.set_process(false)
My issue is that when pressing the button on the controller for activating the game menu, the menu will simply flicker visible for a single frame and then immediately exit. I'm wondering if there's something wrong in this code that is causing this.
Or is my code basically correct, and there's likely something somewhere else going on?
Alternative implementation ideas are also welcome. Thank you for your time! :D