Attention: Here be dragons
This is the latest
(unstable) version of this documentation, which may document features
not available in or compatible with released stable versions of Godot.
Checking the stable version of the documentation...
Timer
Un temporizador de cuenta atrás.
Descripción
The Timer node is a countdown timer and is the simplest way to handle time-based logic in the engine. When a timer reaches the end of its wait_time, it will emit the timeout signal.
After a timer enters the scene tree, it can be manually started with start(). A timer node is also started automatically if autostart is true.
Without requiring much code, a timer node can be added and configured in the editor. The timeout signal it emits can also be connected through the Signals dock in the editor:
func _on_timer_timeout():
print("Time to attack!")
Note: To create a one-shot timer without instantiating a node, use SceneTree.create_timer().
Note: Timers are affected by Engine.time_scale unless ignore_time_scale is true. The higher the time scale, the sooner timers will end. How often a timer processes may depend on the framerate or Engine.physics_ticks_per_second.
Tutoriales
Propiedades
|
||
|
||
|
||
|
||
|
Métodos
is_stopped() const |
|
void |
|
void |
stop() |
Señales
timeout() 🔗
Emitida cuando el temporizador llega al final.
Enumeraciones
enum TimerProcessCallback: 🔗
TimerProcessCallback TIMER_PROCESS_PHYSICS = 0
Actualiza el temporizador en cada frame del proceso de física (véase Node.NOTIFICATION_INTERNAL_PHYSICS_PROCESS).
TimerProcessCallback TIMER_PROCESS_IDLE = 1
Actualiza el temporizador en cada frame del proceso (renderizado) (ver Node.NOTIFICATION_INTERNAL_PROCESS).
Descripciones de Propiedades
Si es true, el temporizador comenzará inmediatamente cuando entre en el árbol de escenas.
Nota: Después de que el temporizador entra en el árbol, esta propiedad se establece automáticamente en false.
Nota: Esta propiedad no hace nada cuando el temporizador se está ejecutando en el editor.
bool ignore_time_scale = false 🔗
Si es true, el temporizador ignorará Engine.time_scale y se actualizará con el tiempo real transcurrido.
Si es true, el temporizador se detendrá después de alcanzar el final. De lo contrario, como por defecto, el temporizador se reiniciará automáticamente.
Si es true, el temporizador se pausa. Un temporizador en pausa no se procesa hasta que esta propiedad se vuelve a establecer en false, incluso cuando se llama a start(). Véase también stop().
TimerProcessCallback process_callback = 1 🔗
void set_timer_process_callback(value: TimerProcessCallback)
TimerProcessCallback get_timer_process_callback()
Especifica cuándo se actualiza el temporizador durante el bucle principal.
float get_time_left()
El tiempo restante del temporizador en segundos. Siempre es 0 si el temporizador está detenido.
Nota: Esta propiedad es de solo lectura y no se puede modificar. Se basa en wait_time.
El tiempo requerido para que el temporizador termine, en segundos. Esta propiedad también se puede establecer cada vez que se llama a start().
Nota: Los temporizadores solo pueden procesarse una vez por frame de física o de proceso (dependiendo del process_callback). Una velocidad de fotogramas inestable puede causar que el temporizador termine de manera inconsistente, lo cual es especialmente notable si el tiempo de espera es menor a aproximadamente 0.05 segundos. Para temporizadores muy cortos, se recomienda escribir tu propio código en lugar de usar un nodo Timer. Los temporizadores también se ven afectados por Engine.time_scale.
Descripciones de Métodos
Devuelve true si el temporizador está detenido o no ha comenzado.
void start(time_sec: float = -1) 🔗
Inicia el temporizador, o reinicia el temporizador si ya se ha iniciado. Falla si el temporizador no está dentro del árbol de escenas. Si time_sec es mayor que 0, este valor se utiliza para wait_time.
Nota: Este método no reanuda un temporizador en pausa. Véase paused.
void stop() 🔗
Detiene el temporizador. Véase también paused. A diferencia de start(), esto se puede llamar de forma segura si el temporizador no está dentro del árbol de escenas.
Nota: Llamar a stop() no emite la señal timeout, ya que no se considera que el temporizador se haya agotado. Si se desea, utiliza $Timer.timeout.emit() después de llamar a stop() para emitir manualmente la señal.