How do I set up the esc key to exit the Godot app?

I have a question that I am stuck in a new 2D project. I added the background of the sprite and there is no problem running the test. I am setting the esc key as "key_exit" on the input card. Then I created node2D as root and added the following script to it:

extends Node2D

func _ready():
   if Input.is_action_pressed("key_exit"):
      get_tree().quit()

      

This does not work. I am trying to create a simple loop that listens for esc key presses and exits when I press the escape key. If I add get_tree (). Quit () without an if clause, it exits as soon as it runs. How do I get him to "listen" to my condition? What am I doing wrong here?

+3


source to share


1 answer


I understood that. I managed to get it to work with the following:



extends Node2D

func _ready():
    set_process(true)

func _process(delta):
   if Input.is_action_pressed("key_exit"):
      get_tree().quit()

      

+5


source







All Articles