2
0

handling_quit_requests.rst 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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. .. tabs::
  17. .. code-tab:: gdscript GDScript
  18. func _notification(what):
  19. if what == MainLoop.NOTIFICATION_WM_QUIT_REQUEST:
  20. get_tree().quit() # default behavior
  21. .. code-tab:: csharp
  22. public override void _Notification(int what)
  23. {
  24. if (what == MainLoop.NotificationWmQuitRequest)
  25. GetTree().Quit(); // default behavior
  26. }
  27. When developing mobile apps, quitting is not desired unless the user is
  28. on the main screen, so the behavior can be changed.
  29. It is important to note that by default, Godot apps have the built-in
  30. behavior to quit when quit is requested, this can be changed:
  31. .. tabs::
  32. .. code-tab:: gdscript GDScript
  33. get_tree().set_auto_accept_quit(false)
  34. .. code-tab:: csharp
  35. GetTree().SetAutoAcceptQuit(false);