0.2.0-dev Download ZIP
85 lines ·5.4 KB Raw
| 1 | <?xml version="1.0" encoding="UTF-8" ?> |
| 2 | <class name="Timer" inherits="Node" api_type="core" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../class.xsd"> |
| 3 | <brief_description> |
| 4 | A countdown timer. |
| 5 | </brief_description> |
| 6 | <description> |
| 7 | 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 [member wait_time], it will emit the [signal timeout] signal. |
| 8 | After a timer enters the scene tree, it can be manually started with [method start]. A timer node is also started automatically if [member autostart] is [code]true[/code]. |
| 9 | Without requiring much code, a timer node can be added and configured in the editor. The [signal timeout] signal it emits can also be connected through the Signals dock in the editor: |
| 10 | [codeblock] |
| 11 | func _on_timer_timeout(): |
| 12 | print("Time to attack!") |
| 13 | [/codeblock] |
| 14 | [b]Note:[/b] To create a one-shot timer without instantiating a node, use [method SceneTree.create_timer]. |
| 15 | [b]Note:[/b] Timers are affected by [member Engine.time_scale] unless [member ignore_time_scale] is [code]true[/code]. The higher the time scale, the sooner timers will end. How often a timer processes may depend on the framerate or [member Engine.physics_ticks_per_second]. |
| 16 | </description> |
| 17 | <tutorials> |
| 18 | <link title="2D Dodge The Creeps Demo">https://godotengine.org/asset-library/asset/2712</link> |
| 19 | </tutorials> |
| 20 | <methods> |
| 21 | <method name="is_stopped" qualifiers="const"> |
| 22 | <return type="bool" /> |
| 23 | <description> |
| 24 | Returns [code]true[/code] if the timer is stopped or has not started. |
| 25 | </description> |
| 26 | </method> |
| 27 | <method name="start"> |
| 28 | <return type="void" /> |
| 29 | <param index="0" name="time_sec" type="float" default="-1" /> |
| 30 | <description> |
| 31 | Starts the timer, or resets the timer if it was started already. Fails if the timer is not inside the scene tree. If [param time_sec] is greater than [code]0[/code], this value is used for the [member wait_time]. |
| 32 | [b]Note:[/b] This method does not resume a paused timer. See [member paused]. |
| 33 | </description> |
| 34 | </method> |
| 35 | <method name="stop"> |
| 36 | <return type="void" /> |
| 37 | <description> |
| 38 | Stops the timer. See also [member paused]. Unlike [method start], this can safely be called if the timer is not inside the scene tree. |
| 39 | [b]Note:[/b] Calling [method stop] does not emit the [signal timeout] signal, as the timer is not considered to have timed out. If this is desired, use [code]$Timer.timeout.emit()[/code] after calling [method stop] to manually emit the signal. |
| 40 | </description> |
| 41 | </method> |
| 42 | </methods> |
| 43 | <members> |
| 44 | <member name="autostart" type="bool" setter="set_autostart" getter="has_autostart" default="false"> |
| 45 | If [code]true[/code], the timer will start immediately when it enters the scene tree. |
| 46 | [b]Note:[/b] After the timer enters the tree, this property is automatically set to [code]false[/code]. |
| 47 | [b]Note:[/b] This property does nothing when the timer is running in the editor. |
| 48 | </member> |
| 49 | <member name="ignore_time_scale" type="bool" setter="set_ignore_time_scale" getter="is_ignoring_time_scale" default="false"> |
| 50 | If [code]true[/code], the timer will ignore [member Engine.time_scale] and update with the real, elapsed time. |
| 51 | </member> |
| 52 | <member name="one_shot" type="bool" setter="set_one_shot" getter="is_one_shot" default="false"> |
| 53 | If [code]true[/code], the timer will stop after reaching the end. Otherwise, as by default, the timer will automatically restart. |
| 54 | </member> |
| 55 | <member name="paused" type="bool" setter="set_paused" getter="is_paused"> |
| 56 | If [code]true[/code], the timer is paused. A paused timer does not process until this property is set back to [code]false[/code], even when [method start] is called. See also [method stop]. |
| 57 | </member> |
| 58 | <member name="process_callback" type="int" setter="set_timer_process_callback" getter="get_timer_process_callback" enum="Timer.TimerProcessCallback" default="1"> |
| 59 | Specifies when the timer is updated during the main loop. |
| 60 | </member> |
| 61 | <member name="time_left" type="float" setter="" getter="get_time_left"> |
| 62 | The timer's remaining time in seconds. This is always [code]0[/code] if the timer is stopped. |
| 63 | [b]Note:[/b] This property is read-only and cannot be modified. It is based on [member wait_time]. |
| 64 | </member> |
| 65 | <member name="wait_time" type="float" setter="set_wait_time" getter="get_wait_time" default="1.0"> |
| 66 | The time required for the timer to end, in seconds. This property can also be set every time [method start] is called. |
| 67 | [b]Note:[/b] Timers can only process once per physics or process frame (depending on the [member process_callback]). An unstable framerate may cause the timer to end inconsistently, which is especially noticeable if the wait time is lower than roughly [code]0.05[/code] seconds. For very short timers, it is recommended to write your own code instead of using a [Timer] node. Timers are also affected by [member Engine.time_scale]. |
| 68 | </member> |
| 69 | </members> |
| 70 | <signals> |
| 71 | <signal name="timeout"> |
| 72 | <description> |
| 73 | Emitted when the timer reaches the end. |
| 74 | </description> |
| 75 | </signal> |
| 76 | </signals> |
| 77 | <constants> |
| 78 | <constant name="TIMER_PROCESS_PHYSICS" value="0" enum="TimerProcessCallback"> |
| 79 | Update the timer every physics process frame (see [constant Node.NOTIFICATION_INTERNAL_PHYSICS_PROCESS]). |
| 80 | </constant> |
| 81 | <constant name="TIMER_PROCESS_IDLE" value="1" enum="TimerProcessCallback"> |
| 82 | Update the timer every process (rendered) frame (see [constant Node.NOTIFICATION_INTERNAL_PROCESS]). |
| 83 | </constant> |
| 84 | </constants> |
| 85 | </class> |