class_curve.rst 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308
  1. :github_url: hide
  2. .. Generated automatically by doc/tools/make_rst.py in Godot's source tree.
  3. .. DO NOT EDIT THIS FILE, but the Curve.xml source instead.
  4. .. The source is found in doc/classes or modules/<name>/doc_classes.
  5. .. _class_Curve:
  6. Curve
  7. =====
  8. **Inherits:** :ref:`Resource<class_Resource>` **<** :ref:`Reference<class_Reference>` **<** :ref:`Object<class_Object>`
  9. A mathematic curve.
  10. Description
  11. -----------
  12. A curve that can be saved and re-used for other objects. By default, it ranges between ``0`` and ``1`` on the Y axis and positions points relative to the ``0.5`` Y position.
  13. Properties
  14. ----------
  15. +---------------------------+--------------------------------------------------------------+---------+
  16. | :ref:`int<class_int>` | :ref:`bake_resolution<class_Curve_property_bake_resolution>` | ``100`` |
  17. +---------------------------+--------------------------------------------------------------+---------+
  18. | :ref:`float<class_float>` | :ref:`max_value<class_Curve_property_max_value>` | ``1.0`` |
  19. +---------------------------+--------------------------------------------------------------+---------+
  20. | :ref:`float<class_float>` | :ref:`min_value<class_Curve_property_min_value>` | ``0.0`` |
  21. +---------------------------+--------------------------------------------------------------+---------+
  22. Methods
  23. -------
  24. +--------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  25. | :ref:`int<class_int>` | :ref:`add_point<class_Curve_method_add_point>` **(** :ref:`Vector2<class_Vector2>` position, :ref:`float<class_float>` left_tangent=0, :ref:`float<class_float>` right_tangent=0, :ref:`TangentMode<enum_Curve_TangentMode>` left_mode=0, :ref:`TangentMode<enum_Curve_TangentMode>` right_mode=0 **)** |
  26. +--------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  27. | void | :ref:`bake<class_Curve_method_bake>` **(** **)** |
  28. +--------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  29. | void | :ref:`clean_dupes<class_Curve_method_clean_dupes>` **(** **)** |
  30. +--------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  31. | void | :ref:`clear_points<class_Curve_method_clear_points>` **(** **)** |
  32. +--------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  33. | :ref:`int<class_int>` | :ref:`get_point_count<class_Curve_method_get_point_count>` **(** **)** |const| |
  34. +--------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  35. | :ref:`TangentMode<enum_Curve_TangentMode>` | :ref:`get_point_left_mode<class_Curve_method_get_point_left_mode>` **(** :ref:`int<class_int>` index **)** |const| |
  36. +--------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  37. | :ref:`float<class_float>` | :ref:`get_point_left_tangent<class_Curve_method_get_point_left_tangent>` **(** :ref:`int<class_int>` index **)** |const| |
  38. +--------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  39. | :ref:`Vector2<class_Vector2>` | :ref:`get_point_position<class_Curve_method_get_point_position>` **(** :ref:`int<class_int>` index **)** |const| |
  40. +--------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  41. | :ref:`TangentMode<enum_Curve_TangentMode>` | :ref:`get_point_right_mode<class_Curve_method_get_point_right_mode>` **(** :ref:`int<class_int>` index **)** |const| |
  42. +--------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  43. | :ref:`float<class_float>` | :ref:`get_point_right_tangent<class_Curve_method_get_point_right_tangent>` **(** :ref:`int<class_int>` index **)** |const| |
  44. +--------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  45. | :ref:`float<class_float>` | :ref:`interpolate<class_Curve_method_interpolate>` **(** :ref:`float<class_float>` offset **)** |const| |
  46. +--------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  47. | :ref:`float<class_float>` | :ref:`interpolate_baked<class_Curve_method_interpolate_baked>` **(** :ref:`float<class_float>` offset **)** |
  48. +--------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  49. | void | :ref:`remove_point<class_Curve_method_remove_point>` **(** :ref:`int<class_int>` index **)** |
  50. +--------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  51. | void | :ref:`set_point_left_mode<class_Curve_method_set_point_left_mode>` **(** :ref:`int<class_int>` index, :ref:`TangentMode<enum_Curve_TangentMode>` mode **)** |
  52. +--------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  53. | void | :ref:`set_point_left_tangent<class_Curve_method_set_point_left_tangent>` **(** :ref:`int<class_int>` index, :ref:`float<class_float>` tangent **)** |
  54. +--------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  55. | :ref:`int<class_int>` | :ref:`set_point_offset<class_Curve_method_set_point_offset>` **(** :ref:`int<class_int>` index, :ref:`float<class_float>` offset **)** |
  56. +--------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  57. | void | :ref:`set_point_right_mode<class_Curve_method_set_point_right_mode>` **(** :ref:`int<class_int>` index, :ref:`TangentMode<enum_Curve_TangentMode>` mode **)** |
  58. +--------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  59. | void | :ref:`set_point_right_tangent<class_Curve_method_set_point_right_tangent>` **(** :ref:`int<class_int>` index, :ref:`float<class_float>` tangent **)** |
  60. +--------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  61. | void | :ref:`set_point_value<class_Curve_method_set_point_value>` **(** :ref:`int<class_int>` index, :ref:`float<class_float>` y **)** |
  62. +--------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  63. Signals
  64. -------
  65. .. _class_Curve_signal_range_changed:
  66. - **range_changed** **(** **)**
  67. Emitted when :ref:`max_value<class_Curve_property_max_value>` or :ref:`min_value<class_Curve_property_min_value>` is changed.
  68. Enumerations
  69. ------------
  70. .. _enum_Curve_TangentMode:
  71. .. _class_Curve_constant_TANGENT_FREE:
  72. .. _class_Curve_constant_TANGENT_LINEAR:
  73. .. _class_Curve_constant_TANGENT_MODE_COUNT:
  74. enum **TangentMode**:
  75. - **TANGENT_FREE** = **0** --- The tangent on this side of the point is user-defined.
  76. - **TANGENT_LINEAR** = **1** --- The curve calculates the tangent on this side of the point as the slope halfway towards the adjacent point.
  77. - **TANGENT_MODE_COUNT** = **2** --- The total number of available tangent modes.
  78. Property Descriptions
  79. ---------------------
  80. .. _class_Curve_property_bake_resolution:
  81. - :ref:`int<class_int>` **bake_resolution**
  82. +-----------+----------------------------+
  83. | *Default* | ``100`` |
  84. +-----------+----------------------------+
  85. | *Setter* | set_bake_resolution(value) |
  86. +-----------+----------------------------+
  87. | *Getter* | get_bake_resolution() |
  88. +-----------+----------------------------+
  89. The number of points to include in the baked (i.e. cached) curve data.
  90. ----
  91. .. _class_Curve_property_max_value:
  92. - :ref:`float<class_float>` **max_value**
  93. +-----------+----------------------+
  94. | *Default* | ``1.0`` |
  95. +-----------+----------------------+
  96. | *Setter* | set_max_value(value) |
  97. +-----------+----------------------+
  98. | *Getter* | get_max_value() |
  99. +-----------+----------------------+
  100. The maximum value the curve can reach.
  101. ----
  102. .. _class_Curve_property_min_value:
  103. - :ref:`float<class_float>` **min_value**
  104. +-----------+----------------------+
  105. | *Default* | ``0.0`` |
  106. +-----------+----------------------+
  107. | *Setter* | set_min_value(value) |
  108. +-----------+----------------------+
  109. | *Getter* | get_min_value() |
  110. +-----------+----------------------+
  111. The minimum value the curve can reach.
  112. Method Descriptions
  113. -------------------
  114. .. _class_Curve_method_add_point:
  115. - :ref:`int<class_int>` **add_point** **(** :ref:`Vector2<class_Vector2>` position, :ref:`float<class_float>` left_tangent=0, :ref:`float<class_float>` right_tangent=0, :ref:`TangentMode<enum_Curve_TangentMode>` left_mode=0, :ref:`TangentMode<enum_Curve_TangentMode>` right_mode=0 **)**
  116. Adds a point to the curve. For each side, if the ``*_mode`` is :ref:`TANGENT_LINEAR<class_Curve_constant_TANGENT_LINEAR>`, the ``*_tangent`` angle (in degrees) uses the slope of the curve halfway to the adjacent point. Allows custom assignments to the ``*_tangent`` angle if ``*_mode`` is set to :ref:`TANGENT_FREE<class_Curve_constant_TANGENT_FREE>`.
  117. ----
  118. .. _class_Curve_method_bake:
  119. - void **bake** **(** **)**
  120. Recomputes the baked cache of points for the curve.
  121. ----
  122. .. _class_Curve_method_clean_dupes:
  123. - void **clean_dupes** **(** **)**
  124. Removes points that are closer than ``CMP_EPSILON`` (0.00001) units to their neighbor on the curve.
  125. ----
  126. .. _class_Curve_method_clear_points:
  127. - void **clear_points** **(** **)**
  128. Removes all points from the curve.
  129. ----
  130. .. _class_Curve_method_get_point_count:
  131. - :ref:`int<class_int>` **get_point_count** **(** **)** |const|
  132. Returns the number of points describing the curve.
  133. ----
  134. .. _class_Curve_method_get_point_left_mode:
  135. - :ref:`TangentMode<enum_Curve_TangentMode>` **get_point_left_mode** **(** :ref:`int<class_int>` index **)** |const|
  136. Returns the left :ref:`TangentMode<enum_Curve_TangentMode>` for the point at ``index``.
  137. ----
  138. .. _class_Curve_method_get_point_left_tangent:
  139. - :ref:`float<class_float>` **get_point_left_tangent** **(** :ref:`int<class_int>` index **)** |const|
  140. Returns the left tangent angle (in degrees) for the point at ``index``.
  141. ----
  142. .. _class_Curve_method_get_point_position:
  143. - :ref:`Vector2<class_Vector2>` **get_point_position** **(** :ref:`int<class_int>` index **)** |const|
  144. Returns the curve coordinates for the point at ``index``.
  145. ----
  146. .. _class_Curve_method_get_point_right_mode:
  147. - :ref:`TangentMode<enum_Curve_TangentMode>` **get_point_right_mode** **(** :ref:`int<class_int>` index **)** |const|
  148. Returns the right :ref:`TangentMode<enum_Curve_TangentMode>` for the point at ``index``.
  149. ----
  150. .. _class_Curve_method_get_point_right_tangent:
  151. - :ref:`float<class_float>` **get_point_right_tangent** **(** :ref:`int<class_int>` index **)** |const|
  152. Returns the right tangent angle (in degrees) for the point at ``index``.
  153. ----
  154. .. _class_Curve_method_interpolate:
  155. - :ref:`float<class_float>` **interpolate** **(** :ref:`float<class_float>` offset **)** |const|
  156. Returns the Y value for the point that would exist at the X position ``offset`` along the curve.
  157. ----
  158. .. _class_Curve_method_interpolate_baked:
  159. - :ref:`float<class_float>` **interpolate_baked** **(** :ref:`float<class_float>` offset **)**
  160. Returns the Y value for the point that would exist at the X position ``offset`` along the curve using the baked cache. Bakes the curve's points if not already baked.
  161. ----
  162. .. _class_Curve_method_remove_point:
  163. - void **remove_point** **(** :ref:`int<class_int>` index **)**
  164. Removes the point at ``index`` from the curve.
  165. ----
  166. .. _class_Curve_method_set_point_left_mode:
  167. - void **set_point_left_mode** **(** :ref:`int<class_int>` index, :ref:`TangentMode<enum_Curve_TangentMode>` mode **)**
  168. Sets the left :ref:`TangentMode<enum_Curve_TangentMode>` for the point at ``index`` to ``mode``.
  169. ----
  170. .. _class_Curve_method_set_point_left_tangent:
  171. - void **set_point_left_tangent** **(** :ref:`int<class_int>` index, :ref:`float<class_float>` tangent **)**
  172. Sets the left tangent angle for the point at ``index`` to ``tangent``.
  173. ----
  174. .. _class_Curve_method_set_point_offset:
  175. - :ref:`int<class_int>` **set_point_offset** **(** :ref:`int<class_int>` index, :ref:`float<class_float>` offset **)**
  176. Sets the offset from ``0.5``.
  177. ----
  178. .. _class_Curve_method_set_point_right_mode:
  179. - void **set_point_right_mode** **(** :ref:`int<class_int>` index, :ref:`TangentMode<enum_Curve_TangentMode>` mode **)**
  180. Sets the right :ref:`TangentMode<enum_Curve_TangentMode>` for the point at ``index`` to ``mode``.
  181. ----
  182. .. _class_Curve_method_set_point_right_tangent:
  183. - void **set_point_right_tangent** **(** :ref:`int<class_int>` index, :ref:`float<class_float>` tangent **)**
  184. Sets the right tangent angle for the point at ``index`` to ``tangent``.
  185. ----
  186. .. _class_Curve_method_set_point_value:
  187. - void **set_point_value** **(** :ref:`int<class_int>` index, :ref:`float<class_float>` y **)**
  188. Assigns the vertical position ``y`` to the point at ``index``.
  189. .. |virtual| replace:: :abbr:`virtual (This method should typically be overridden by the user to have any effect.)`
  190. .. |const| replace:: :abbr:`const (This method has no side effects. It doesn't modify any of the instance's member variables.)`
  191. .. |vararg| replace:: :abbr:`vararg (This method accepts any number of arguments after the ones described here.)`