Documentation
¶
Overview ¶
The graphics.gd/classdb/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 Instance.WaitTime, it will emit the Instance.OnTimeout signal.
After a timer enters the scene tree, it can be manually started with Instance.Start. A timer node is also started automatically if Instance.Autostart is true.
Without requiring much code, a timer node can be added and configured in the editor. The Instance.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 graphics.gd/classdb/SceneTree.Instance.CreateTimer.
Note: Timers are affected by graphics.gd/classdb/Engine.TimeScale unless Instance.IgnoreTimeScale is true. The higher the time scale, the sooner timers will end. How often a timer processes may depend on the framerate or graphics.gd/classdb/Engine.PhysicsTicksPerSecond.
Index ¶
- type Advanced
- type Any
- type Expanded
- type Extension
- type ID
- type Instance
- func (self Instance) AsNode() Node.Instance
- func (self Instance) AsObject() [1]gd.Object
- func (self Instance) AsTimer() Instance
- func (self Instance) Autostart() bool
- func (self Instance) ID() ID
- func (self Instance) IgnoreTimeScale() bool
- func (self Instance) IsStopped() bool
- func (self Instance) OnTimeout(cb func(), flags ...Signal.Flags)
- func (self Instance) OneShot() bool
- func (self Instance) Paused() bool
- func (self Instance) ProcessCallback() TimerProcessCallback
- func (self Instance) SetAutostart(value bool)
- func (self Instance) SetIgnoreTimeScale(value bool)
- func (self *Instance) SetObject(obj [1]gd.Object) bool
- func (self Instance) SetOneShot(value bool)
- func (self Instance) SetPaused(value bool)
- func (self Instance) SetProcessCallback(value TimerProcessCallback)
- func (self Instance) SetWaitTime(value Float.X)
- func (self Instance) Start()
- func (self Instance) Stop()
- func (self Instance) TimeLeft() Float.X
- func (self Instance) Virtual(name string) reflect.Value
- func (self Instance) WaitTime() Float.X
- type TimerProcessCallback
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 Expanded ¶
func (Expanded) 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 Instance.WaitTime.
Note: This method does not resume a paused timer. See Instance.Paused.
type Extension ¶
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
type 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.
type Instance ¶
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 (Instance) IgnoreTimeScale ¶
func (Instance) ProcessCallback ¶
func (self Instance) ProcessCallback() TimerProcessCallback
func (Instance) SetAutostart ¶
func (Instance) SetIgnoreTimeScale ¶
func (Instance) SetOneShot ¶
func (Instance) SetProcessCallback ¶
func (self Instance) SetProcessCallback(value TimerProcessCallback)
func (Instance) SetWaitTime ¶
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 Instance.WaitTime.
Note: This method does not resume a paused timer. See Instance.Paused.
func (Instance) Stop ¶
func (self Instance) Stop()
Stops the timer. See also Instance.Paused. Unlike Instance.Start, this can safely be called if the timer is not inside the scene tree.
Note: Calling Instance.Stop does not emit the Instance.OnTimeout signal, as the timer is not considered to have timed out. If this is desired, use $Timer.timeout.emit() after calling Instance.Stop to manually emit the signal.
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 )