1. Create a new Scene by clicking the + sign on the right side of the "coin" tab.
2. Create a new Node by clicking the + sign under the Scene tab or by pressing the Ctrl-A key combination.
3. In the Create New Node window that appears, search for Area2D in the Search line and select it, and click the Create button.
4. While the "Area2D" Node is selected, under the "Inspector" tab, in the "Collision" row, select the value 2 from the "Mask" table.
We are doing this process only to check the Player on Layer 2.
5. Change the name "Area2D" to "Endzone".
6. Save it as endzone.tscn file in the res://scenes directory in the window that opens with the Ctrl-S key combination.
7. Select "game" Scene.
8. Add the "scenes\endzone.tscn" file to the "game" Scene by dragging and dropping it in the "FileSystem" tab or by clicking the "Link" button under the "Scene" tab and selecting the "scenes\endzone.tscn" file from the window that appears and clicking the "Open" button.
9. To reuse the "Endzone" Node for all objects in the game, add a new Node by clicking the + sign under the Scene tab or by pressing the Ctrl-A key combination while the "Endzone" Node is selected.
10. In the Create New Node window that appears, search for and select the expression CollisionShape2D in the Search line and click on the Create button.
11. While "CollisionShape2D" is selected, select "New WorldBoundaryShape2D" from the box to the right of the "Shape" line under the "Inspector" tab.
12. While "game" Scene and "Endzone" Node are selected, align the "CollisionShape2D" Node under the main scene.
13. While "endzone" Scene and "Endzone" Node are selected, click on the "Attach a new or existing script to selected node" button:
14. In the window that opens, change the value in the "Template" line to Object:Empty and click the button on the far right of the "Path" line.
15. In the window that opens, go to the "scripts" directory, select the "endzone.gd" file, and click the "Open" button.
16. When we return to the previous window, click the "Create" button.
17. While the "Endzone" Node is selected, double-click on the "body_entered" signal under the "Node" tab on the right.
18. Click on the "Connect" button in the window that appears.
19. A new function is added to the script content.
extends Area2D
func _on_body_entered(body: Node2D) -> void:
pass # Replace with function body.
20. When the player falls down and enters the "Endzone" area, instead of restarting the game immediately, add a "Timer" Node that will provide a short delay first, while the "Endzone" Node is selected, create a new Node by clicking the + sign under the Scene tab or by pressing the Ctrl-A key combination.
21. In the Create New Node window that appears, search for Timer in the Search line and select it, and click the Create button.
22. While the "Timer" Node is selected, under the "Inspector" tab, change the "Wait Time" value to "0.6". Check the "One Shot" On box.
23. Drag the "Timer" Node with the mouse and bring it to the function in the script code. Hold down the "Ctrl" key before dropping it. This will create a variable called "timer". This variable automatically finds the Node with the value it receives.
extends Area2D
@onready var timer: Timer = $Timer
func _on_body_entered(body: Node2D) -> void:
pass # Replace with function body.
24. To start the timer, add the timer.start() line to the function. The final version of the script will be as follows:
extends Area2D
@onready var timer: Timer = $Timer
func _on_body_entered(body: Node2D) -> void:
timer.start()
25. When the timer expires, we can use a new signal to create some code that we need to trigger. With the "Timer" Node selected, double-click the "timeout()" signal in the "Node" tab.
26. Click on the "Connect" button in the window that appears.
27. Edit the function content below.
extends Area2D
@onready var timer: Timer = $Timer
func _on_body_entered(body: Node2D) -> void:
timer.start()
func _on_timer_timeout() -> void:
get_tree().reload_current_scene()
When we save all scenes with Ctrl-S keys and run the game, when the Player falls down, the game will be restarted after 0.6 seconds of waiting with the timer.