Start a Timer
Part of the Game Rules section of Coddy's Godot journey. Lesson 2 of 29.
The lighthouse timer started by itself because its autostart was on. Often a timer should wait, like a cooldown that starts when you attack.
This castle's Timer has autostart off. Call start() to set it going:
$Timer.start()It then sends timeout every second. Calling start() again starts the count over.
The script already raises the gate 35 pixels on every timeout.
Challenge
EasyOpen the gate when the player presses E.
- In
_process(), check whetheractionwas just pressed. - If it was, call
$Timer.start().
Press Play, then E: the gate rises 35 pixels every second. Then Check.
Try it yourself
extends Node2D
func _ready():
$Timer.timeout.connect(_on_timer_timeout)
func _process(delta):
pass
func _on_timer_timeout():
$Gate.position.y -= 35
All lessons in Game Rules
Practice on your own: Godot playground