class_timer.rst 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279
  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:** To create a one-shot timer without instantiating a node, use :ref:`SceneTree.create_timer<class_SceneTree_method_create_timer>`.
  16. .. rst-class:: classref-introduction-group
  17. Tutorials
  18. ---------
  19. - `2D Dodge The Creeps Demo <https://godotengine.org/asset-library/asset/515>`__
  20. .. rst-class:: classref-reftable-group
  21. Properties
  22. ----------
  23. .. table::
  24. :widths: auto
  25. +--------------------------------------------------------------+----------------------------------------------------------------+-----------+
  26. | :ref:`bool<class_bool>` | :ref:`autostart<class_Timer_property_autostart>` | ``false`` |
  27. +--------------------------------------------------------------+----------------------------------------------------------------+-----------+
  28. | :ref:`bool<class_bool>` | :ref:`one_shot<class_Timer_property_one_shot>` | ``false`` |
  29. +--------------------------------------------------------------+----------------------------------------------------------------+-----------+
  30. | :ref:`bool<class_bool>` | :ref:`paused<class_Timer_property_paused>` | |
  31. +--------------------------------------------------------------+----------------------------------------------------------------+-----------+
  32. | :ref:`TimerProcessCallback<enum_Timer_TimerProcessCallback>` | :ref:`process_callback<class_Timer_property_process_callback>` | ``1`` |
  33. +--------------------------------------------------------------+----------------------------------------------------------------+-----------+
  34. | :ref:`float<class_float>` | :ref:`time_left<class_Timer_property_time_left>` | |
  35. +--------------------------------------------------------------+----------------------------------------------------------------+-----------+
  36. | :ref:`float<class_float>` | :ref:`wait_time<class_Timer_property_wait_time>` | ``1.0`` |
  37. +--------------------------------------------------------------+----------------------------------------------------------------+-----------+
  38. .. rst-class:: classref-reftable-group
  39. Methods
  40. -------
  41. .. table::
  42. :widths: auto
  43. +-------------------------+------------------------------------------------------------------------------------------+
  44. | :ref:`bool<class_bool>` | :ref:`is_stopped<class_Timer_method_is_stopped>` **(** **)** |const| |
  45. +-------------------------+------------------------------------------------------------------------------------------+
  46. | void | :ref:`start<class_Timer_method_start>` **(** :ref:`float<class_float>` time_sec=-1 **)** |
  47. +-------------------------+------------------------------------------------------------------------------------------+
  48. | void | :ref:`stop<class_Timer_method_stop>` **(** **)** |
  49. +-------------------------+------------------------------------------------------------------------------------------+
  50. .. rst-class:: classref-section-separator
  51. ----
  52. .. rst-class:: classref-descriptions-group
  53. Signals
  54. -------
  55. .. _class_Timer_signal_timeout:
  56. .. rst-class:: classref-signal
  57. **timeout** **(** **)**
  58. Emitted when the timer reaches 0.
  59. .. rst-class:: classref-section-separator
  60. ----
  61. .. rst-class:: classref-descriptions-group
  62. Enumerations
  63. ------------
  64. .. _enum_Timer_TimerProcessCallback:
  65. .. rst-class:: classref-enumeration
  66. enum **TimerProcessCallback**:
  67. .. _class_Timer_constant_TIMER_PROCESS_PHYSICS:
  68. .. rst-class:: classref-enumeration-constant
  69. :ref:`TimerProcessCallback<enum_Timer_TimerProcessCallback>` **TIMER_PROCESS_PHYSICS** = ``0``
  70. Update the timer during the physics step at each frame (fixed framerate processing).
  71. .. _class_Timer_constant_TIMER_PROCESS_IDLE:
  72. .. rst-class:: classref-enumeration-constant
  73. :ref:`TimerProcessCallback<enum_Timer_TimerProcessCallback>` **TIMER_PROCESS_IDLE** = ``1``
  74. Update the timer during the idle time at each frame.
  75. .. rst-class:: classref-section-separator
  76. ----
  77. .. rst-class:: classref-descriptions-group
  78. Property Descriptions
  79. ---------------------
  80. .. _class_Timer_property_autostart:
  81. .. rst-class:: classref-property
  82. :ref:`bool<class_bool>` **autostart** = ``false``
  83. .. rst-class:: classref-property-setget
  84. - void **set_autostart** **(** :ref:`bool<class_bool>` value **)**
  85. - :ref:`bool<class_bool>` **has_autostart** **(** **)**
  86. If ``true``, the timer will automatically start when entering the scene tree.
  87. \ **Note:** This property is automatically set to ``false`` after the timer enters the scene tree and starts.
  88. .. rst-class:: classref-item-separator
  89. ----
  90. .. _class_Timer_property_one_shot:
  91. .. rst-class:: classref-property
  92. :ref:`bool<class_bool>` **one_shot** = ``false``
  93. .. rst-class:: classref-property-setget
  94. - void **set_one_shot** **(** :ref:`bool<class_bool>` value **)**
  95. - :ref:`bool<class_bool>` **is_one_shot** **(** **)**
  96. If ``true``, the timer will stop when reaching 0. If ``false``, it will restart.
  97. .. rst-class:: classref-item-separator
  98. ----
  99. .. _class_Timer_property_paused:
  100. .. rst-class:: classref-property
  101. :ref:`bool<class_bool>` **paused**
  102. .. rst-class:: classref-property-setget
  103. - void **set_paused** **(** :ref:`bool<class_bool>` value **)**
  104. - :ref:`bool<class_bool>` **is_paused** **(** **)**
  105. If ``true``, the timer is paused and will not process until it is unpaused again, even if :ref:`start<class_Timer_method_start>` is called.
  106. .. rst-class:: classref-item-separator
  107. ----
  108. .. _class_Timer_property_process_callback:
  109. .. rst-class:: classref-property
  110. :ref:`TimerProcessCallback<enum_Timer_TimerProcessCallback>` **process_callback** = ``1``
  111. .. rst-class:: classref-property-setget
  112. - void **set_timer_process_callback** **(** :ref:`TimerProcessCallback<enum_Timer_TimerProcessCallback>` value **)**
  113. - :ref:`TimerProcessCallback<enum_Timer_TimerProcessCallback>` **get_timer_process_callback** **(** **)**
  114. Processing callback. See :ref:`TimerProcessCallback<enum_Timer_TimerProcessCallback>`.
  115. .. rst-class:: classref-item-separator
  116. ----
  117. .. _class_Timer_property_time_left:
  118. .. rst-class:: classref-property
  119. :ref:`float<class_float>` **time_left**
  120. .. rst-class:: classref-property-setget
  121. - :ref:`float<class_float>` **get_time_left** **(** **)**
  122. The timer's remaining time in seconds. Returns 0 if the timer is inactive.
  123. \ **Note:** This value is read-only and cannot be set. It is based on :ref:`wait_time<class_Timer_property_wait_time>`, which can be set using :ref:`start<class_Timer_method_start>`.
  124. .. rst-class:: classref-item-separator
  125. ----
  126. .. _class_Timer_property_wait_time:
  127. .. rst-class:: classref-property
  128. :ref:`float<class_float>` **wait_time** = ``1.0``
  129. .. rst-class:: classref-property-setget
  130. - void **set_wait_time** **(** :ref:`float<class_float>` value **)**
  131. - :ref:`float<class_float>` **get_wait_time** **(** **)**
  132. The wait time in seconds.
  133. \ **Note:** Timers can only emit once per rendered frame at most (or once per physics frame if :ref:`process_callback<class_Timer_property_process_callback>` is :ref:`TIMER_PROCESS_PHYSICS<class_Timer_constant_TIMER_PROCESS_PHYSICS>`). This means very low wait times (lower than 0.05 seconds) will behave in significantly different ways depending on the rendered framerate. For very low wait times, it is recommended to use a process loop in a script instead of using a Timer node.
  134. .. rst-class:: classref-section-separator
  135. ----
  136. .. rst-class:: classref-descriptions-group
  137. Method Descriptions
  138. -------------------
  139. .. _class_Timer_method_is_stopped:
  140. .. rst-class:: classref-method
  141. :ref:`bool<class_bool>` **is_stopped** **(** **)** |const|
  142. Returns ``true`` if the timer is stopped.
  143. .. rst-class:: classref-item-separator
  144. ----
  145. .. _class_Timer_method_start:
  146. .. rst-class:: classref-method
  147. void **start** **(** :ref:`float<class_float>` time_sec=-1 **)**
  148. Starts the timer. Sets :ref:`wait_time<class_Timer_property_wait_time>` to ``time_sec`` if ``time_sec > 0``. This also resets the remaining time to :ref:`wait_time<class_Timer_property_wait_time>`.
  149. \ **Note:** This method will not resume a paused timer. See :ref:`paused<class_Timer_property_paused>`.
  150. .. rst-class:: classref-item-separator
  151. ----
  152. .. _class_Timer_method_stop:
  153. .. rst-class:: classref-method
  154. void **stop** **(** **)**
  155. Stops the timer.
  156. .. |virtual| replace:: :abbr:`virtual (This method should typically be overridden by the user to have any effect.)`
  157. .. |const| replace:: :abbr:`const (This method has no side effects. It doesn't modify any of the instance's member variables.)`
  158. .. |vararg| replace:: :abbr:`vararg (This method accepts any number of arguments after the ones described here.)`
  159. .. |constructor| replace:: :abbr:`constructor (This method is used to construct a type.)`
  160. .. |static| replace:: :abbr:`static (This method doesn't need an instance to be called, so it can be called directly using the class name.)`
  161. .. |operator| replace:: :abbr:`operator (This method describes a valid operator to use with this type as left-hand operand.)`