Skip to content

Commit eb81478

Browse files
authored
Merge pull request #357 from pigdevstudio/pause-demo
Improve Pause demo
2 parents 029706d + 85afe1b commit eb81478

File tree

2 files changed

+32
-41
lines changed

2 files changed

+32
-41
lines changed

misc/pause/pause_button.gd

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
extends Button
2+
3+
func _ready():
4+
#This ensures that this Node won't be paused, allowing it to
5+
#process even when the SceneTree is paused. Without that it would
6+
#not be able to unpause the game. Note that you can set this through
7+
#the inspector as well
8+
pause_mode = Node.PAUSE_MODE_PROCESS
9+
10+
11+
func _toggled(button_pressed):
12+
#Pause or unpause the SceneTree based on whether the button is
13+
#toggled on or off
14+
get_tree().paused = button_pressed
15+
if button_pressed:
16+
text = "Unpause"
17+
else:
18+
text = "Pause"

misc/pause/spinpause.tscn

Lines changed: 14 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[gd_scene load_steps=4 format=2]
22

3-
[ext_resource path="res://spinpause.gd" type="Script" id=1]
3+
[ext_resource path="res://pause_button.gd" type="Script" id=1]
44

55
[sub_resource type="CubeMesh" id=1]
66

@@ -21,7 +21,6 @@ tracks/0/keys = {
2121
}
2222

2323
[node name="pause_scene" type="Spatial"]
24-
script = ExtResource( 1 )
2524

2625
[node name="cube" type="MeshInstance" parent="."]
2726
mesh = SubResource( 1 )
@@ -40,43 +39,17 @@ anims/spin = SubResource( 2 )
4039
transform = Transform( 0.792992, 0.251051, -0.555101, 0, 0.911149, 0.412078, 0.609232, -0.326775, 0.722534, -3.05357, 1.80053, 3.64099 )
4140
spot_range = 6.0
4241

43-
[node name="pause" type="Button" parent="."]
44-
margin_left = 24.0
45-
margin_top = 24.0
46-
margin_right = 120.0
47-
margin_bottom = 56.0
48-
size_flags_horizontal = 2
49-
size_flags_vertical = 2
50-
text = "PAUSE!"
51-
52-
[node name="pause_popup" type="PopupPanel" parent="."]
42+
[node name="pause_button" type="Button" parent="."]
5343
pause_mode = 2
54-
self_modulate = Color( 1, 1, 1, 0.7 )
55-
margin_left = 185.0
56-
margin_top = 72.0
57-
margin_right = 638.0
58-
margin_bottom = 433.0
59-
size_flags_horizontal = 2
60-
size_flags_vertical = 2
61-
62-
[node name="text" type="Label" parent="pause_popup"]
63-
margin_left = 4.0
64-
margin_top = 4.0
65-
margin_right = 449.0
66-
margin_bottom = 357.0
67-
size_flags_horizontal = 2
68-
size_flags_vertical = 0
69-
text = "The game has been paused! Nodes are not processing anymore, but this popup can still process!"
70-
autowrap = true
71-
72-
[node name="unpause" type="Button" parent="pause_popup"]
73-
margin_left = 4.0
74-
margin_top = 4.0
75-
margin_right = 449.0
76-
margin_bottom = 357.0
77-
size_flags_horizontal = 2
78-
size_flags_vertical = 2
79-
text = "UN-PAUSE!"
80-
81-
[connection signal="pressed" from="pause" to="." method="_on_pause_pressed"]
82-
[connection signal="pressed" from="pause_popup/unpause" to="." method="_on_unpause_pressed"]
44+
anchor_left = 0.5
45+
anchor_top = 0.5
46+
anchor_right = 0.5
47+
anchor_bottom = 0.5
48+
margin_left = -125.0
49+
margin_top = 150.0
50+
margin_right = 125.0
51+
margin_bottom = 200.0
52+
rect_pivot_offset = Vector2( 123, 25 )
53+
toggle_mode = true
54+
text = "Pause"
55+
script = ExtResource( 1 )

0 commit comments

Comments
 (0)