0 votes

In the _input(event): I have if Input.is_action_pressed("menu"): (menu is bound to the Esc key) to show the menu when I press Esc (it simply .show() a controll node (the menu), if the menu controll node .isvisible() == false or .hide() the menu controll node, if the menu controll node .isvisible() == true) and hold it, it open and closes the menu (and so on) continiously.
I don't want that, I would prefer that it only shows/hides the menu once, regardless of whether I pressed Esc once or hold it.

Is there a way of doing it? Or do I need to make a "workaround" with Input.is_action_just_released()?

Thank you very much!

asked Jul 2 in Projects by Liemaeu (98 points)

1 Answer

+3 votes
Best answer

Don't use the Input singleton in _input(). You already have a reference to an individual input: event.

func _input(event):
    if event.is_action_pressed("menu"):
        visible = not visible

This will only fire once when you press the key.

For more about how to use inputs, and the difference between Input and _input(), please read: https://docs.godotengine.org/en/3.2/tutorials/inputs/input_examples.html

answered Jul 2 by kidscancode (17,716 points)
selected Jul 6 by Liemaeu
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.