終了リクエストの処理

終了

ほとんどのプラットフォームには、アプリケーションの終了を要求するオプションがあります。デスクトップでは、これは通常、ウィンドウのタイトルバーにある "x" アイコンで行われます。Androidでは、戻るボタンを使用して、メイン画面上で終了します(終了以外の場合は戻ります)。

通知の処理

デスクトッププラットフォームでは、MainLoop には、終了が要求されたときにすべてのノードに送信される特別な MainLoop.NOTIFICATION_WM_QUIT_REQUEST 通知があります。

Androidでは、代わりに MainLoop.NOTIFICATION_WM_GO_BACK_REQUEST が送信されます。プロジェクト設定で Application -> Config -> Quit On Go Back がチェックされている場合(規定値)、[戻る]ボタンを押すとアプリケーションが終了します。

注釈

iOSデバイスには物理的な [戻る] ボタンが付いていないため、iOSでは MainLoop.NOTIFICATION_WM_GO_BACK_REQUEST はサポートされません。

通知の処理は、(任意のノードで) 次のように行われます:

func _notification(what):
    if what == MainLoop.NOTIFICATION_WM_QUIT_REQUEST:
        get_tree().quit() # default behavior

モバイルアプリを開発する場合、ユーザーがメイン画面にいる場合を除き、終了することは望ましくないため、動作を変更できます。

デフォルトでは、Godotアプリには、終了が要求されたときに終了する組み込みの動作があり、これを変更できることに注意してください:

get_tree().set_auto_accept_quit(false)

Sending your own quit notification

While forcing the application to close can be done by calling SceneTree.quit, doing so will not send the quit notification. This means the function described above won't be called. Quitting by calling SceneTree.quit will not allow custom actions to complete (such as saving, confirming the quit, or debugging), even if you try to delay the line that forces the quit.

Instead, you should send a quit request:

get_tree().notification(MainLoop.NOTIFICATION_WM_QUIT_REQUEST)