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
EasyPause the game when the last life is lost.
- Find the
ifthat shows Game Over. - Inside it, under that line, set
get_tree().pausedtotrue.
Press Play and lose three lives: Game Over shows and the player cannot move. Then Check.
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
All lessons in Game Rules
Practice on your own: Godot playground