Godot - ゲーム退出ボタン

ゲーム退出機能を開発する。

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
# Godot 4.1

extends Node

@onready var exit_but = Button

func _ready():
    exit_but = get_node("Button") # ノードをゲット
    exit_but.pressed.connect(self._button_pressed) # ボタン押下チェック

func _process(delta):
    pass

# 退出申請を発送
func _button_pressed():
    get_tree().root.propagate_notification(NOTIFICATION_WM_CLOSE_REQUEST)

# 退出申請を受け時ゲームを終わる
func _notification(what):
    if what == NOTIFICATION_WM_CLOSE_REQUEST:
        get_tree().quit() # default behavior
Hugo で構築されています。
テーマ StackJimmy によって設計されています。