handling_quit_requests.rst 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. .. _doc_handling_quit_requests:
  2. Handling quit requests
  3. ======================
  4. Quitting
  5. --------
  6. Most platforms have the option to request the application to quit. On
  7. desktops, this is usually done with the "x" icon on the window titlebar.
  8. On Android, the back button is used to quit when on the main screen (and
  9. to go back otherwise).
  10. Handling the notification
  11. -------------------------
  12. The :ref:`MainLoop <class_MainLoop>`
  13. has a special notification that is sent to all nodes when quit is
  14. requested: MainLoop.NOTIFICATION_WM_QUIT.
  15. Handling it is done as follows (on any node):
  16. ::
  17. func _notification(what):
  18. if (what == MainLoop.NOTIFICATION_WM_QUIT_REQUEST):
  19. get_tree().quit() # default behavior
  20. When developing mobile apps, quitting is not desired unless the user is
  21. on the main screen, so the behavior can be changed.
  22. It is important to note that by default, Godot apps have the built-in
  23. behavior to quit when quit is requested, this can be changed:
  24. ::
  25. get_tree().set_auto_accept_quit(false)