Add escape-to-pause

This commit is contained in:
Jennie Robinson Faber 2026-05-10 19:41:03 +01:00
parent f6d66e0101
commit 1d6b5c35ca
4 changed files with 60 additions and 0 deletions

View file

@ -10,6 +10,7 @@
[ext_resource type="PackedScene" path="res://scenes/component_spawn.tscn" id="9_0tnpc"]
[ext_resource type="PackedScene" path="res://scenes/end_screen.tscn" id="10_endsc"]
[ext_resource type="PackedScene" path="res://scenes/title_screen.tscn" id="11_title"]
[ext_resource type="PackedScene" path="res://scenes/pause_menu.tscn" id="12_pause"]
[node name="Game" type="Node3D" unique_id=1456297160]
script = ExtResource("1_lbhrr")
@ -41,3 +42,5 @@ stream = ExtResource("6_gee14")
[node name="EndScreen" parent="." instance=ExtResource("10_endsc")]
[node name="TitleScreen" parent="." instance=ExtResource("11_title")]
[node name="PauseMenu" parent="." instance=ExtResource("12_pause")]

22
scenes/pause_menu.gd Normal file
View file

@ -0,0 +1,22 @@
extends CanvasLayer
var _enabled := false
func _ready():
visible = false
EventBus.game_started.connect(_on_game_started)
func _on_game_started():
_enabled = true
func _unhandled_input(event):
if not _enabled:
return
if event is InputEventKey and event.pressed and not event.echo and event.keycode == KEY_ESCAPE:
_toggle()
get_viewport().set_input_as_handled()
func _toggle():
var paused := not get_tree().paused
get_tree().paused = paused
visible = paused

1
scenes/pause_menu.gd.uid Normal file
View file

@ -0,0 +1 @@
uid://chssreaybnwn8

34
scenes/pause_menu.tscn Normal file
View file

@ -0,0 +1,34 @@
[gd_scene load_steps=2 format=3]
[ext_resource type="Script" path="res://scenes/pause_menu.gd" id="1"]
[node name="PauseMenu" type="CanvasLayer"]
layer = 25
process_mode = 3
script = ExtResource("1")
[node name="Dim" type="ColorRect" parent="."]
anchor_right = 1.0
anchor_bottom = 1.0
mouse_filter = 2
color = Color(0, 0, 0, 0.7)
[node name="Center" type="CenterContainer" parent="."]
anchor_right = 1.0
anchor_bottom = 1.0
mouse_filter = 1
[node name="Column" type="VBoxContainer" parent="Center"]
theme_override_constants/separation = 16
[node name="Title" type="Label" parent="Center/Column"]
text = "PAUSED"
horizontal_alignment = 1
theme_override_colors/font_color = Color(1, 1, 1, 1)
theme_override_font_sizes/font_size = 64
[node name="Prompt" type="Label" parent="Center/Column"]
text = "ESC TO RESUME"
horizontal_alignment = 1
theme_override_colors/font_color = Color(0.7, 0.7, 0.7, 1)
theme_override_font_sizes/font_size = 24