The Timer Node
Part of the Game Rules section of Coddy's Godot journey. Lesson 1 of 29.
A Timer node counts down. When it reaches zero, it sends its timeout signal and starts again. Games use timers for bombs, spawns and blinking lights.
This lighthouse has a Timer that counts one second. It starts on its own when the game starts. Open the Scene tab to see it.
Connect timeout to a function, the same way you connected body_entered:
func _ready():
$Timer.timeout.connect(_on_timer_timeout)
func _on_timer_timeout():
print("One more second")Now _on_timer_timeout() runs once every second.
Challenge
EasyMake the lighthouse blink:
- In
_ready(), connect$Timer.timeoutto_on_timer_timeout. - In
_on_timer_timeout(), turn$Lightoff when it is on, and on when it is off.
Try it yourself
extends Node2D
func _ready():
pass
func _on_timer_timeout():
pass
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