Pause the Game
Part of the Game Rules section of Coddy's Godot journey. Lesson 13 of 29.
After Game Over, the player can still walk around. Pause the whole game with one line:
get_tree().paused = trueget_tree() is the scene tree, which holds every node in the game. While it is paused, _process and _physics_process stop running. Timers stop counting, and nothing moves or collides. The screen keeps showing the last frame.
get_tree().paused = false starts everything again.
Challenge
EasyWhen the last life is lost, pause the game. Inside the if, under the line that shows Game Over, set get_tree().paused to true.
Try it yourself
extends Node2D
var lives = 3
func _ready():
$HUD/Lives.text = "Lives: %d" % lives
$Player.hurt.connect(_on_player_hurt)
func _on_player_hurt():
lives -= 1
$HUD/Lives.text = "Lives: %d" % lives
if lives == 0:
$HUD/GameOver.visible = true
This lesson includes a short quiz. Start the lesson to answer it and track your progress.
All lessons in Game Rules
Practice on your own: Godot playground