Loading...
Loading...
Design a game over screen with score display, retry button, and main menu option.
Create a new scene with Control as root. Name it 'GameOverScreen'. Add a ColorRect background (semi-transparent black: rgba(0,0,0,180)). Add a Label for 'GAME OVER' text (large, bold, red or white). Add another Label for final score: `@onready var score_label = $ScoreLabel`.
Add two Button nodes: 'Play Again' and 'Main Menu'. Name them 'RetryButton' and 'MenuButton'. Style them with custom colors or themes. Position them vertically below the score using a VBoxContainer for clean alignment.
Create the GameOverScreen.gd script. Add a variable to receive the final score: `var final_score = 0`. In `_ready()`: Update the score display: `score_label.text = 'Final Score: ' + str(final_score)`. Connect button signals: `$RetryButton.pressed.connect(_on_retry_pressed)`, `$MenuButton.pressed.connect(_on_menu_pressed)`.
Implement button functions: `func _on_retry_pressed(): get_tree().change_scene_to_file('res://scenes/Game.tscn')` (reloads the game level). `func _on_menu_pressed(): get_tree().change_scene_to_file('res://scenes/MainMenu.tscn')` (returns to main menu).
Show the game over screen from your game: In your Player or GameManager script, when player dies: `var game_over = preload('res://scenes/GameOverScreen.tscn').instantiate()`, `game_over.final_score = score`, `get_tree().current_scene.add_child(game_over)`. Add a pause effect: `get_tree().paused = true` to freeze the game while game over is displayed.