Timer

package
v0.0.0-...-357ca8a Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 20, 2025 License: MIT Imports: 24 Imported by: 0

Documentation

Overview

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 WaitTime, it will emit the OnTimeout 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 OnTimeout signal it emits can also be connected through the Node dock in the editor:

package main

import "fmt"

func OnTimerTimeout() {
	fmt.Println("Time to attack!")
}

Note: To create a one-shot timer without instantiating a node, use SceneTree.CreateTimer.

Note: Timers are affected by Engine.TimeScale unless IgnoreTimeScale is true. The higher the time scale, the sooner timers will end. How often a timer processes may depend on the framerate or Engine.PhysicsTicksPerSecond.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Advanced

type Advanced = class

Advanced exposes a 1:1 low-level instance of the class, undocumented, for those who know what they are doing.

type Any

type Any interface {
	gd.IsClass
	AsTimer() Instance
}

type Expanded

type Expanded = MoreArgs

type Extension

type Extension[T gdclass.Interface] struct{ gdclass.Extension[T, Instance] }

Extension can be embedded in a new struct to create an extension of this class. T should be the type that is embedding this Extension

func (*Extension[T]) AsNode

func (self *Extension[T]) AsNode() Node.Instance

func (*Extension[T]) AsObject

func (self *Extension[T]) AsObject() [1]gd.Object

func (*Extension[T]) AsTimer

func (self *Extension[T]) AsTimer() Instance

type ID

type ID Object.ID

ID is a typed object ID (reference) to an instance of this class, use it to store references to objects with unknown lifetimes, as an ID will not panic on use if the underlying object has been destroyed.

func (ID) Instance

func (id ID) Instance() (Instance, bool)

type Instance

type Instance [1]gdclass.Timer

Instance of the class with convieniently typed arguments and results.

var Nil Instance

Nil is a nil/null instance of the class. Equivalent to the zero value.

func New

func New() Instance

func (Instance) AsNode

func (self Instance) AsNode() Node.Instance

func (Instance) AsObject

func (self Instance) AsObject() [1]gd.Object

func (Instance) AsTimer

func (self Instance) AsTimer() Instance

func (Instance) Autostart

func (self Instance) Autostart() bool

If true, the timer will start immediately when it enters the scene tree.

Note: After the timer enters the tree, this property is automatically set to false.

Note: This property does nothing when the timer is running in the editor.

func (Instance) ID

func (self Instance) ID() ID

func (Instance) IgnoreTimeScale

func (self Instance) IgnoreTimeScale() bool

If true, the timer will ignore Engine.TimeScale and update with the real, elapsed time.

func (Instance) IsStopped

func (self Instance) IsStopped() bool

Returns true if the timer is stopped or has not started.

func (Instance) MoreArgs

func (self Instance) MoreArgs() MoreArgs

MoreArgs enables certain functions to be called with additional 'optional' arguments.

func (Instance) OnTimeout

func (self Instance) OnTimeout(cb func(), flags ...Signal.Flags)

Emitted when the timer reaches the end.

func (Instance) OneShot

func (self Instance) OneShot() bool

If true, the timer will stop after reaching the end. Otherwise, as by default, the timer will automatically restart.

func (Instance) Paused

func (self Instance) Paused() bool

If true, the timer is paused. A paused timer does not process until this property is set back to false, even when Start is called. See also Stop.

func (Instance) ProcessCallback

func (self Instance) ProcessCallback() TimerProcessCallback

Specifies when the timer is updated during the main loop.

func (Instance) SetAutostart

func (self Instance) SetAutostart(value bool)

SetAutostart sets the property returned by [HasAutostart].

func (Instance) SetIgnoreTimeScale

func (self Instance) SetIgnoreTimeScale(value bool)

SetIgnoreTimeScale sets the property returned by [IsIgnoringTimeScale].

func (*Instance) SetObject

func (self *Instance) SetObject(obj [1]gd.Object) bool

func (Instance) SetOneShot

func (self Instance) SetOneShot(value bool)

SetOneShot sets the property returned by [IsOneShot].

func (Instance) SetPaused

func (self Instance) SetPaused(value bool)

SetPaused sets the property returned by [IsPaused].

func (Instance) SetProcessCallback

func (self Instance) SetProcessCallback(value TimerProcessCallback)

SetProcessCallback sets the property returned by [GetTimerProcessCallback].

func (Instance) SetWaitTime

func (self Instance) SetWaitTime(value Float.X)

SetWaitTime sets the property returned by [GetWaitTime].

func (Instance) Start

func (self Instance) Start()

Starts the timer, or resets the timer if it was started already. Fails if the timer is not inside the scene tree. If 'time_sec' is greater than 0, this value is used for the WaitTime.

Note: This method does not resume a paused timer. See Paused.

func (Instance) Stop

func (self Instance) Stop()

Stops the timer. See also Paused. Unlike Start, this can safely be called if the timer is not inside the scene tree.

Note: Calling Stop does not emit the OnTimeout signal, as the timer is not considered to have timed out. If this is desired, use $Timer.timeout.emit() after calling Stop to manually emit the signal.

func (Instance) TimeLeft

func (self Instance) TimeLeft() Float.X

The timer's remaining time in seconds. This is always 0 if the timer is stopped.

Note: This property is read-only and cannot be modified. It is based on WaitTime.

func (Instance) Virtual

func (self Instance) Virtual(name string) reflect.Value

func (Instance) WaitTime

func (self Instance) WaitTime() Float.X

The time required for the timer to end, in seconds. This property can also be set every time Start is called.

Note: Timers can only process once per physics or process frame (depending on the ProcessCallback). An unstable framerate may cause the timer to end inconsistently, which is especially noticeable if the wait time is lower than roughly 0.05 seconds. For very short timers, it is recommended to write your own code instead of using a Timer node. Timers are also affected by Engine.TimeScale.

type MoreArgs

type MoreArgs [1]gdclass.Timer

MoreArgs is a container for Instance functions with additional 'optional' arguments.

func (MoreArgs) Start

func (self MoreArgs) Start(time_sec Float.X)

Starts the timer, or resets the timer if it was started already. Fails if the timer is not inside the scene tree. If 'time_sec' is greater than 0, this value is used for the WaitTime.

Note: This method does not resume a paused timer. See Paused.

type TimerProcessCallback

type TimerProcessCallback int //gd:Timer.TimerProcessCallback
const (
	// Update the timer every physics process frame (see [Node.NotificationInternalPhysicsProcess]).
	TimerProcessPhysics TimerProcessCallback = 0
	// Update the timer every process (rendered) frame (see [Node.NotificationInternalProcess]).
	TimerProcessIdle TimerProcessCallback = 1
)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL