class_timer.rst 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. :github_url: hide
  2. .. Generated automatically by doc/tools/makerst.py in Godot's source tree.
  3. .. DO NOT EDIT THIS FILE, but the Timer.xml source instead.
  4. .. The source is found in doc/classes or modules/<name>/doc_classes.
  5. .. _class_Timer:
  6. Timer
  7. =====
  8. **Inherits:** :ref:`Node<class_Node>` **<** :ref:`Object<class_Object>`
  9. A countdown timer.
  10. Description
  11. -----------
  12. Counts down a specified interval and emits a signal on reaching 0. Can be set to repeat or "one-shot" mode.
  13. **Note:** To create a one-shot timer without instantiating a node, use :ref:`SceneTree.create_timer<class_SceneTree_method_create_timer>`.
  14. Tutorials
  15. ---------
  16. - `2D Dodge The Creeps Demo <https://godotengine.org/asset-library/asset/515>`_
  17. Properties
  18. ----------
  19. +------------------------------------------------------+--------------------------------------------------------+-----------+
  20. | :ref:`bool<class_bool>` | :ref:`autostart<class_Timer_property_autostart>` | ``false`` |
  21. +------------------------------------------------------+--------------------------------------------------------+-----------+
  22. | :ref:`bool<class_bool>` | :ref:`one_shot<class_Timer_property_one_shot>` | ``false`` |
  23. +------------------------------------------------------+--------------------------------------------------------+-----------+
  24. | :ref:`bool<class_bool>` | :ref:`paused<class_Timer_property_paused>` | |
  25. +------------------------------------------------------+--------------------------------------------------------+-----------+
  26. | :ref:`TimerProcessMode<enum_Timer_TimerProcessMode>` | :ref:`process_mode<class_Timer_property_process_mode>` | ``1`` |
  27. +------------------------------------------------------+--------------------------------------------------------+-----------+
  28. | :ref:`float<class_float>` | :ref:`time_left<class_Timer_property_time_left>` | |
  29. +------------------------------------------------------+--------------------------------------------------------+-----------+
  30. | :ref:`float<class_float>` | :ref:`wait_time<class_Timer_property_wait_time>` | ``1.0`` |
  31. +------------------------------------------------------+--------------------------------------------------------+-----------+
  32. Methods
  33. -------
  34. +-------------------------+------------------------------------------------------------------------------------------+
  35. | :ref:`bool<class_bool>` | :ref:`is_stopped<class_Timer_method_is_stopped>` **(** **)** |const| |
  36. +-------------------------+------------------------------------------------------------------------------------------+
  37. | void | :ref:`start<class_Timer_method_start>` **(** :ref:`float<class_float>` time_sec=-1 **)** |
  38. +-------------------------+------------------------------------------------------------------------------------------+
  39. | void | :ref:`stop<class_Timer_method_stop>` **(** **)** |
  40. +-------------------------+------------------------------------------------------------------------------------------+
  41. Signals
  42. -------
  43. .. _class_Timer_signal_timeout:
  44. - **timeout** **(** **)**
  45. Emitted when the timer reaches 0.
  46. Enumerations
  47. ------------
  48. .. _enum_Timer_TimerProcessMode:
  49. .. _class_Timer_constant_TIMER_PROCESS_PHYSICS:
  50. .. _class_Timer_constant_TIMER_PROCESS_IDLE:
  51. enum **TimerProcessMode**:
  52. - **TIMER_PROCESS_PHYSICS** = **0** --- Update the timer during the physics step at each frame (fixed framerate processing).
  53. - **TIMER_PROCESS_IDLE** = **1** --- Update the timer during the idle time at each frame.
  54. Property Descriptions
  55. ---------------------
  56. .. _class_Timer_property_autostart:
  57. - :ref:`bool<class_bool>` **autostart**
  58. +-----------+----------------------+
  59. | *Default* | ``false`` |
  60. +-----------+----------------------+
  61. | *Setter* | set_autostart(value) |
  62. +-----------+----------------------+
  63. | *Getter* | has_autostart() |
  64. +-----------+----------------------+
  65. If ``true``, the timer will automatically start when entering the scene tree.
  66. **Note:** This property is automatically set to ``false`` after the timer enters the scene tree and starts.
  67. ----
  68. .. _class_Timer_property_one_shot:
  69. - :ref:`bool<class_bool>` **one_shot**
  70. +-----------+---------------------+
  71. | *Default* | ``false`` |
  72. +-----------+---------------------+
  73. | *Setter* | set_one_shot(value) |
  74. +-----------+---------------------+
  75. | *Getter* | is_one_shot() |
  76. +-----------+---------------------+
  77. If ``true``, the timer will stop when reaching 0. If ``false``, it will restart.
  78. ----
  79. .. _class_Timer_property_paused:
  80. - :ref:`bool<class_bool>` **paused**
  81. +----------+-------------------+
  82. | *Setter* | set_paused(value) |
  83. +----------+-------------------+
  84. | *Getter* | is_paused() |
  85. +----------+-------------------+
  86. 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.
  87. ----
  88. .. _class_Timer_property_process_mode:
  89. - :ref:`TimerProcessMode<enum_Timer_TimerProcessMode>` **process_mode**
  90. +-----------+-------------------------------+
  91. | *Default* | ``1`` |
  92. +-----------+-------------------------------+
  93. | *Setter* | set_timer_process_mode(value) |
  94. +-----------+-------------------------------+
  95. | *Getter* | get_timer_process_mode() |
  96. +-----------+-------------------------------+
  97. Processing mode. See :ref:`TimerProcessMode<enum_Timer_TimerProcessMode>`.
  98. ----
  99. .. _class_Timer_property_time_left:
  100. - :ref:`float<class_float>` **time_left**
  101. +----------+-----------------+
  102. | *Getter* | get_time_left() |
  103. +----------+-----------------+
  104. The timer's remaining time in seconds. Returns 0 if the timer is inactive.
  105. **Note:** You cannot set this value. To change the timer's remaining time, use :ref:`start<class_Timer_method_start>`.
  106. ----
  107. .. _class_Timer_property_wait_time:
  108. - :ref:`float<class_float>` **wait_time**
  109. +-----------+----------------------+
  110. | *Default* | ``1.0`` |
  111. +-----------+----------------------+
  112. | *Setter* | set_wait_time(value) |
  113. +-----------+----------------------+
  114. | *Getter* | get_wait_time() |
  115. +-----------+----------------------+
  116. Wait time in seconds.
  117. Method Descriptions
  118. -------------------
  119. .. _class_Timer_method_is_stopped:
  120. - :ref:`bool<class_bool>` **is_stopped** **(** **)** |const|
  121. Returns ``true`` if the timer is stopped.
  122. ----
  123. .. _class_Timer_method_start:
  124. - void **start** **(** :ref:`float<class_float>` time_sec=-1 **)**
  125. Starts the timer. Sets ``wait_time`` to ``time_sec`` if ``time_sec > 0``. This also resets the remaining time to ``wait_time``.
  126. **Note:** this method will not resume a paused timer. See :ref:`paused<class_Timer_property_paused>`.
  127. ----
  128. .. _class_Timer_method_stop:
  129. - void **stop** **(** **)**
  130. Stops the timer.
  131. .. |virtual| replace:: :abbr:`virtual (This method should typically be overridden by the user to have any effect.)`
  132. .. |const| replace:: :abbr:`const (This method has no side effects. It doesn't modify any of the instance's member variables.)`
  133. .. |vararg| replace:: :abbr:`vararg (This method accepts any number of arguments after the ones described here.)`