handling_quit_request.rst 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. Handling Quit Request
  2. =====================
  3. Quitting
  4. --------
  5. Most platforms have the option to request the application to quit. On
  6. desktops, this is usually done with the "x" icon on the window titlebar.
  7. On Android, the back button is used to quit when on the main screen (and
  8. to go back otherwise).
  9. Handling the Notification
  10. -------------------------
  11. The
  12. `MainLoop <https://github.com/okamstudio/godot/wiki/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)
  26. *Juan Linietsky, Ariel Manzur, Distributed under the terms of the `CC
  27. By <https://creativecommons.org/licenses/by/3.0/legalcode>`__ license.*