class_timer.rst 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  1. :github_url: hide
  2. .. DO NOT EDIT THIS FILE!!!
  3. .. Generated automatically from Godot engine sources.
  4. .. Generator: https://github.com/godotengine/godot/tree/master/doc/tools/make_rst.py.
  5. .. XML source: https://github.com/godotengine/godot/tree/master/doc/classes/Timer.xml.
  6. .. _class_Timer:
  7. Timer
  8. =====
  9. **Inherits:** :ref:`Node<class_Node>` **<** :ref:`Object<class_Object>`
  10. A countdown timer.
  11. .. rst-class:: classref-introduction-group
  12. Description
  13. -----------
  14. Counts down a specified interval and emits a signal on reaching 0. Can be set to repeat or "one-shot" mode.
  15. \ **Note:** Timers are affected by :ref:`Engine.time_scale<class_Engine_property_time_scale>`, a higher scale means quicker timeouts, and vice versa.
  16. \ **Note:** To create a one-shot timer without instantiating a node, use :ref:`SceneTree.create_timer<class_SceneTree_method_create_timer>`.
  17. .. rst-class:: classref-introduction-group
  18. Tutorials
  19. ---------
  20. - `2D Dodge The Creeps Demo <https://godotengine.org/asset-library/asset/515>`__
  21. .. rst-class:: classref-reftable-group
  22. Properties
  23. ----------
  24. .. table::
  25. :widths: auto
  26. +--------------------------------------------------------------+----------------------------------------------------------------+-----------+
  27. | :ref:`bool<class_bool>` | :ref:`autostart<class_Timer_property_autostart>` | ``false`` |
  28. +--------------------------------------------------------------+----------------------------------------------------------------+-----------+
  29. | :ref:`bool<class_bool>` | :ref:`one_shot<class_Timer_property_one_shot>` | ``false`` |
  30. +--------------------------------------------------------------+----------------------------------------------------------------+-----------+
  31. | :ref:`bool<class_bool>` | :ref:`paused<class_Timer_property_paused>` | |
  32. +--------------------------------------------------------------+----------------------------------------------------------------+-----------+
  33. | :ref:`TimerProcessCallback<enum_Timer_TimerProcessCallback>` | :ref:`process_callback<class_Timer_property_process_callback>` | ``1`` |
  34. +--------------------------------------------------------------+----------------------------------------------------------------+-----------+
  35. | :ref:`float<class_float>` | :ref:`time_left<class_Timer_property_time_left>` | |
  36. +--------------------------------------------------------------+----------------------------------------------------------------+-----------+
  37. | :ref:`float<class_float>` | :ref:`wait_time<class_Timer_property_wait_time>` | ``1.0`` |
  38. +--------------------------------------------------------------+----------------------------------------------------------------+-----------+
  39. .. rst-class:: classref-reftable-group
  40. Methods
  41. -------
  42. .. table::
  43. :widths: auto
  44. +-------------------------+------------------------------------------------------------------------------------------+
  45. | :ref:`bool<class_bool>` | :ref:`is_stopped<class_Timer_method_is_stopped>` **(** **)** |const| |
  46. +-------------------------+------------------------------------------------------------------------------------------+
  47. | void | :ref:`start<class_Timer_method_start>` **(** :ref:`float<class_float>` time_sec=-1 **)** |
  48. +-------------------------+------------------------------------------------------------------------------------------+
  49. | void | :ref:`stop<class_Timer_method_stop>` **(** **)** |
  50. +-------------------------+------------------------------------------------------------------------------------------+
  51. .. rst-class:: classref-section-separator
  52. ----
  53. .. rst-class:: classref-descriptions-group
  54. Signals
  55. -------
  56. .. _class_Timer_signal_timeout:
  57. .. rst-class:: classref-signal
  58. **timeout** **(** **)**
  59. Emitted when the timer reaches the end.
  60. .. rst-class:: classref-section-separator
  61. ----
  62. .. rst-class:: classref-descriptions-group
  63. Enumerations
  64. ------------
  65. .. _enum_Timer_TimerProcessCallback:
  66. .. rst-class:: classref-enumeration
  67. enum **TimerProcessCallback**:
  68. .. _class_Timer_constant_TIMER_PROCESS_PHYSICS:
  69. .. rst-class:: classref-enumeration-constant
  70. :ref:`TimerProcessCallback<enum_Timer_TimerProcessCallback>` **TIMER_PROCESS_PHYSICS** = ``0``
  71. Update the timer every physics process frame (see :ref:`Node.NOTIFICATION_INTERNAL_PHYSICS_PROCESS<class_Node_constant_NOTIFICATION_INTERNAL_PHYSICS_PROCESS>`).
  72. .. _class_Timer_constant_TIMER_PROCESS_IDLE:
  73. .. rst-class:: classref-enumeration-constant
  74. :ref:`TimerProcessCallback<enum_Timer_TimerProcessCallback>` **TIMER_PROCESS_IDLE** = ``1``
  75. Update the timer every process (rendered) frame (see :ref:`Node.NOTIFICATION_INTERNAL_PROCESS<class_Node_constant_NOTIFICATION_INTERNAL_PROCESS>`).
  76. .. rst-class:: classref-section-separator
  77. ----
  78. .. rst-class:: classref-descriptions-group
  79. Property Descriptions
  80. ---------------------
  81. .. _class_Timer_property_autostart:
  82. .. rst-class:: classref-property
  83. :ref:`bool<class_bool>` **autostart** = ``false``
  84. .. rst-class:: classref-property-setget
  85. - void **set_autostart** **(** :ref:`bool<class_bool>` value **)**
  86. - :ref:`bool<class_bool>` **has_autostart** **(** **)**
  87. If ``true``, the timer will start immediately when it enters the scene tree.
  88. \ **Note:** After the timer enters the tree, this property is automatically set to ``false``.
  89. .. rst-class:: classref-item-separator
  90. ----
  91. .. _class_Timer_property_one_shot:
  92. .. rst-class:: classref-property
  93. :ref:`bool<class_bool>` **one_shot** = ``false``
  94. .. rst-class:: classref-property-setget
  95. - void **set_one_shot** **(** :ref:`bool<class_bool>` value **)**
  96. - :ref:`bool<class_bool>` **is_one_shot** **(** **)**
  97. If ``true``, the timer will stop after reaching the end. Otherwise, as by default, the timer will automatically restart.
  98. .. rst-class:: classref-item-separator
  99. ----
  100. .. _class_Timer_property_paused:
  101. .. rst-class:: classref-property
  102. :ref:`bool<class_bool>` **paused**
  103. .. rst-class:: classref-property-setget
  104. - void **set_paused** **(** :ref:`bool<class_bool>` value **)**
  105. - :ref:`bool<class_bool>` **is_paused** **(** **)**
  106. If ``true``, the timer is paused. A paused timer does not process until this property is set back to ``false``, even when :ref:`start<class_Timer_method_start>` is called.
  107. .. rst-class:: classref-item-separator
  108. ----
  109. .. _class_Timer_property_process_callback:
  110. .. rst-class:: classref-property
  111. :ref:`TimerProcessCallback<enum_Timer_TimerProcessCallback>` **process_callback** = ``1``
  112. .. rst-class:: classref-property-setget
  113. - void **set_timer_process_callback** **(** :ref:`TimerProcessCallback<enum_Timer_TimerProcessCallback>` value **)**
  114. - :ref:`TimerProcessCallback<enum_Timer_TimerProcessCallback>` **get_timer_process_callback** **(** **)**
  115. Specifies when the timer is updated during the main loop (see :ref:`TimerProcessCallback<enum_Timer_TimerProcessCallback>`).
  116. .. rst-class:: classref-item-separator
  117. ----
  118. .. _class_Timer_property_time_left:
  119. .. rst-class:: classref-property
  120. :ref:`float<class_float>` **time_left**
  121. .. rst-class:: classref-property-setget
  122. - :ref:`float<class_float>` **get_time_left** **(** **)**
  123. The timer's remaining time in seconds. This is always ``0`` if the timer is stopped.
  124. \ **Note:** This property is read-only and cannot be modified. It is based on :ref:`wait_time<class_Timer_property_wait_time>`.
  125. .. rst-class:: classref-item-separator
  126. ----
  127. .. _class_Timer_property_wait_time:
  128. .. rst-class:: classref-property
  129. :ref:`float<class_float>` **wait_time** = ``1.0``
  130. .. rst-class:: classref-property-setget
  131. - void **set_wait_time** **(** :ref:`float<class_float>` value **)**
  132. - :ref:`float<class_float>` **get_wait_time** **(** **)**
  133. The time required for the timer to end, in seconds. This property can also be set every time :ref:`start<class_Timer_method_start>` is called.
  134. \ **Note:** Timers can only process once per physics or process frame (depending on the :ref:`process_callback<class_Timer_property_process_callback>`). 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 :ref:`Engine.time_scale<class_Engine_property_time_scale>`.
  135. .. rst-class:: classref-section-separator
  136. ----
  137. .. rst-class:: classref-descriptions-group
  138. Method Descriptions
  139. -------------------
  140. .. _class_Timer_method_is_stopped:
  141. .. rst-class:: classref-method
  142. :ref:`bool<class_bool>` **is_stopped** **(** **)** |const|
  143. Returns ``true`` if the timer is stopped or has not started.
  144. .. rst-class:: classref-item-separator
  145. ----
  146. .. _class_Timer_method_start:
  147. .. rst-class:: classref-method
  148. void **start** **(** :ref:`float<class_float>` time_sec=-1 **)**
  149. Starts the timer, if it was not started already. Fails if the timer is not inside the tree. If ``time_sec`` is greater than ``0``, this value is used for the :ref:`wait_time<class_Timer_property_wait_time>`.
  150. \ **Note:** This method does not resume a paused timer. See :ref:`paused<class_Timer_property_paused>`.
  151. .. rst-class:: classref-item-separator
  152. ----
  153. .. _class_Timer_method_stop:
  154. .. rst-class:: classref-method
  155. void **stop** **(** **)**
  156. Stops the timer.
  157. .. |virtual| replace:: :abbr:`virtual (This method should typically be overridden by the user to have any effect.)`
  158. .. |const| replace:: :abbr:`const (This method has no side effects. It doesn't modify any of the instance's member variables.)`
  159. .. |vararg| replace:: :abbr:`vararg (This method accepts any number of arguments after the ones described here.)`
  160. .. |constructor| replace:: :abbr:`constructor (This method is used to construct a type.)`
  161. .. |static| replace:: :abbr:`static (This method doesn't need an instance to be called, so it can be called directly using the class name.)`
  162. .. |operator| replace:: :abbr:`operator (This method describes a valid operator to use with this type as left-hand operand.)`
  163. .. |bitfield| replace:: :abbr:`BitField (This value is an integer composed as a bitmask of the following flags.)`