处理退出请求¶
退出¶
大多数平台都可以选择请求应用程序退出。在桌面上,这通常是通过窗口标题栏上的“X”图标完成的。在Android上,后退按钮用于在主屏幕上退出(否则返回)。
处理通知¶
这个 MainLoop 有一个特殊通知,在请求退出时发送给所有节点:mainloop.notification_wm_quit。
处理方法如下(在任何节点上):
func _notification(what):
if what == MainLoop.NOTIFICATION_WM_QUIT_REQUEST:
get_tree().quit() # default behavior
public override void _Notification(int what)
{
if (what == MainLoop.NotificationWmQuitRequest)
GetTree().Quit(); // default behavior
}
在开发移动应用程序时,除非用户在主屏幕上,否则不需要退出,因此可以更改行为。
需要注意的是,在默认情况下,godot应用程序具有在请求退出时退出的内置行为,这可以更改:
get_tree().set_auto_accept_quit(false)
GetTree().SetAutoAcceptQuit(false);