class_line2d.rst 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394
  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 Line2D.xml source instead.
  4. .. The source is found in doc/classes or modules/<name>/doc_classes.
  5. .. _class_Line2D:
  6. Line2D
  7. ======
  8. **Inherits:** :ref:`Node2D<class_Node2D>` **<** :ref:`CanvasItem<class_CanvasItem>` **<** :ref:`Node<class_Node>` **<** :ref:`Object<class_Object>`
  9. A 2D line.
  10. Description
  11. -----------
  12. A line through several points in 2D space.
  13. Tutorials
  14. ---------
  15. - `Matrix Transform Demo <https://godotengine.org/asset-library/asset/584>`__
  16. - `2.5D Demo <https://godotengine.org/asset-library/asset/583>`__
  17. Properties
  18. ----------
  19. +-----------------------------------------------------+---------------------------------------------------------------+--------------------------+
  20. | :ref:`bool<class_bool>` | :ref:`antialiased<class_Line2D_property_antialiased>` | ``false`` |
  21. +-----------------------------------------------------+---------------------------------------------------------------+--------------------------+
  22. | :ref:`LineCapMode<enum_Line2D_LineCapMode>` | :ref:`begin_cap_mode<class_Line2D_property_begin_cap_mode>` | ``0`` |
  23. +-----------------------------------------------------+---------------------------------------------------------------+--------------------------+
  24. | :ref:`Color<class_Color>` | :ref:`default_color<class_Line2D_property_default_color>` | ``Color(1, 1, 1, 1)`` |
  25. +-----------------------------------------------------+---------------------------------------------------------------+--------------------------+
  26. | :ref:`LineCapMode<enum_Line2D_LineCapMode>` | :ref:`end_cap_mode<class_Line2D_property_end_cap_mode>` | ``0`` |
  27. +-----------------------------------------------------+---------------------------------------------------------------+--------------------------+
  28. | :ref:`Gradient<class_Gradient>` | :ref:`gradient<class_Line2D_property_gradient>` | |
  29. +-----------------------------------------------------+---------------------------------------------------------------+--------------------------+
  30. | :ref:`LineJointMode<enum_Line2D_LineJointMode>` | :ref:`joint_mode<class_Line2D_property_joint_mode>` | ``0`` |
  31. +-----------------------------------------------------+---------------------------------------------------------------+--------------------------+
  32. | :ref:`PackedVector2Array<class_PackedVector2Array>` | :ref:`points<class_Line2D_property_points>` | ``PackedVector2Array()`` |
  33. +-----------------------------------------------------+---------------------------------------------------------------+--------------------------+
  34. | :ref:`int<class_int>` | :ref:`round_precision<class_Line2D_property_round_precision>` | ``8`` |
  35. +-----------------------------------------------------+---------------------------------------------------------------+--------------------------+
  36. | :ref:`float<class_float>` | :ref:`sharp_limit<class_Line2D_property_sharp_limit>` | ``2.0`` |
  37. +-----------------------------------------------------+---------------------------------------------------------------+--------------------------+
  38. | :ref:`Texture2D<class_Texture2D>` | :ref:`texture<class_Line2D_property_texture>` | |
  39. +-----------------------------------------------------+---------------------------------------------------------------+--------------------------+
  40. | :ref:`LineTextureMode<enum_Line2D_LineTextureMode>` | :ref:`texture_mode<class_Line2D_property_texture_mode>` | ``0`` |
  41. +-----------------------------------------------------+---------------------------------------------------------------+--------------------------+
  42. | :ref:`float<class_float>` | :ref:`width<class_Line2D_property_width>` | ``10.0`` |
  43. +-----------------------------------------------------+---------------------------------------------------------------+--------------------------+
  44. | :ref:`Curve<class_Curve>` | :ref:`width_curve<class_Line2D_property_width_curve>` | |
  45. +-----------------------------------------------------+---------------------------------------------------------------+--------------------------+
  46. Methods
  47. -------
  48. +-------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------+
  49. | void | :ref:`add_point<class_Line2D_method_add_point>` **(** :ref:`Vector2<class_Vector2>` position, :ref:`int<class_int>` at_position=-1 **)** |
  50. +-------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------+
  51. | void | :ref:`clear_points<class_Line2D_method_clear_points>` **(** **)** |
  52. +-------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------+
  53. | :ref:`int<class_int>` | :ref:`get_point_count<class_Line2D_method_get_point_count>` **(** **)** |const| |
  54. +-------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------+
  55. | :ref:`Vector2<class_Vector2>` | :ref:`get_point_position<class_Line2D_method_get_point_position>` **(** :ref:`int<class_int>` i **)** |const| |
  56. +-------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------+
  57. | void | :ref:`remove_point<class_Line2D_method_remove_point>` **(** :ref:`int<class_int>` i **)** |
  58. +-------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------+
  59. | void | :ref:`set_point_position<class_Line2D_method_set_point_position>` **(** :ref:`int<class_int>` i, :ref:`Vector2<class_Vector2>` position **)** |
  60. +-------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------+
  61. Enumerations
  62. ------------
  63. .. _enum_Line2D_LineJointMode:
  64. .. _class_Line2D_constant_LINE_JOINT_SHARP:
  65. .. _class_Line2D_constant_LINE_JOINT_BEVEL:
  66. .. _class_Line2D_constant_LINE_JOINT_ROUND:
  67. enum **LineJointMode**:
  68. - **LINE_JOINT_SHARP** = **0** --- The line's joints will be pointy. If ``sharp_limit`` is greater than the rotation of a joint, it becomes a bevel joint instead.
  69. - **LINE_JOINT_BEVEL** = **1** --- The line's joints will be bevelled/chamfered.
  70. - **LINE_JOINT_ROUND** = **2** --- The line's joints will be rounded.
  71. ----
  72. .. _enum_Line2D_LineCapMode:
  73. .. _class_Line2D_constant_LINE_CAP_NONE:
  74. .. _class_Line2D_constant_LINE_CAP_BOX:
  75. .. _class_Line2D_constant_LINE_CAP_ROUND:
  76. enum **LineCapMode**:
  77. - **LINE_CAP_NONE** = **0** --- Don't draw a line cap.
  78. - **LINE_CAP_BOX** = **1** --- Draws the line cap as a box.
  79. - **LINE_CAP_ROUND** = **2** --- Draws the line cap as a circle.
  80. ----
  81. .. _enum_Line2D_LineTextureMode:
  82. .. _class_Line2D_constant_LINE_TEXTURE_NONE:
  83. .. _class_Line2D_constant_LINE_TEXTURE_TILE:
  84. .. _class_Line2D_constant_LINE_TEXTURE_STRETCH:
  85. enum **LineTextureMode**:
  86. - **LINE_TEXTURE_NONE** = **0** --- Takes the left pixels of the texture and renders it over the whole line.
  87. - **LINE_TEXTURE_TILE** = **1** --- Tiles the texture over the line. :ref:`CanvasItem.texture_repeat<class_CanvasItem_property_texture_repeat>` of the ``Line2D`` node must be :ref:`CanvasItem.TEXTURE_REPEAT_ENABLED<class_CanvasItem_constant_TEXTURE_REPEAT_ENABLED>` or :ref:`CanvasItem.TEXTURE_REPEAT_MIRROR<class_CanvasItem_constant_TEXTURE_REPEAT_MIRROR>` for it to work properly.
  88. - **LINE_TEXTURE_STRETCH** = **2** --- Stretches the texture across the line. :ref:`CanvasItem.texture_repeat<class_CanvasItem_property_texture_repeat>` of the ``Line2D`` node must be :ref:`CanvasItem.TEXTURE_REPEAT_DISABLED<class_CanvasItem_constant_TEXTURE_REPEAT_DISABLED>` for best results.
  89. Property Descriptions
  90. ---------------------
  91. .. _class_Line2D_property_antialiased:
  92. - :ref:`bool<class_bool>` **antialiased**
  93. +-----------+------------------------+
  94. | *Default* | ``false`` |
  95. +-----------+------------------------+
  96. | *Setter* | set_antialiased(value) |
  97. +-----------+------------------------+
  98. | *Getter* | get_antialiased() |
  99. +-----------+------------------------+
  100. If ``true``, the line's border will be anti-aliased.
  101. \ **Note:** Line2D is not accelerated by batching when being anti-aliased.
  102. ----
  103. .. _class_Line2D_property_begin_cap_mode:
  104. - :ref:`LineCapMode<enum_Line2D_LineCapMode>` **begin_cap_mode**
  105. +-----------+---------------------------+
  106. | *Default* | ``0`` |
  107. +-----------+---------------------------+
  108. | *Setter* | set_begin_cap_mode(value) |
  109. +-----------+---------------------------+
  110. | *Getter* | get_begin_cap_mode() |
  111. +-----------+---------------------------+
  112. Controls the style of the line's first point. Use :ref:`LineCapMode<enum_Line2D_LineCapMode>` constants.
  113. ----
  114. .. _class_Line2D_property_default_color:
  115. - :ref:`Color<class_Color>` **default_color**
  116. +-----------+--------------------------+
  117. | *Default* | ``Color(1, 1, 1, 1)`` |
  118. +-----------+--------------------------+
  119. | *Setter* | set_default_color(value) |
  120. +-----------+--------------------------+
  121. | *Getter* | get_default_color() |
  122. +-----------+--------------------------+
  123. The line's color. Will not be used if a gradient is set.
  124. ----
  125. .. _class_Line2D_property_end_cap_mode:
  126. - :ref:`LineCapMode<enum_Line2D_LineCapMode>` **end_cap_mode**
  127. +-----------+-------------------------+
  128. | *Default* | ``0`` |
  129. +-----------+-------------------------+
  130. | *Setter* | set_end_cap_mode(value) |
  131. +-----------+-------------------------+
  132. | *Getter* | get_end_cap_mode() |
  133. +-----------+-------------------------+
  134. Controls the style of the line's last point. Use :ref:`LineCapMode<enum_Line2D_LineCapMode>` constants.
  135. ----
  136. .. _class_Line2D_property_gradient:
  137. - :ref:`Gradient<class_Gradient>` **gradient**
  138. +----------+---------------------+
  139. | *Setter* | set_gradient(value) |
  140. +----------+---------------------+
  141. | *Getter* | get_gradient() |
  142. +----------+---------------------+
  143. The gradient is drawn through the whole line from start to finish. The default color will not be used if a gradient is set.
  144. ----
  145. .. _class_Line2D_property_joint_mode:
  146. - :ref:`LineJointMode<enum_Line2D_LineJointMode>` **joint_mode**
  147. +-----------+-----------------------+
  148. | *Default* | ``0`` |
  149. +-----------+-----------------------+
  150. | *Setter* | set_joint_mode(value) |
  151. +-----------+-----------------------+
  152. | *Getter* | get_joint_mode() |
  153. +-----------+-----------------------+
  154. The style for the points between the start and the end.
  155. ----
  156. .. _class_Line2D_property_points:
  157. - :ref:`PackedVector2Array<class_PackedVector2Array>` **points**
  158. +-----------+--------------------------+
  159. | *Default* | ``PackedVector2Array()`` |
  160. +-----------+--------------------------+
  161. | *Setter* | set_points(value) |
  162. +-----------+--------------------------+
  163. | *Getter* | get_points() |
  164. +-----------+--------------------------+
  165. The points that form the lines. The line is drawn between every point set in this array. Points are interpreted as local vectors.
  166. ----
  167. .. _class_Line2D_property_round_precision:
  168. - :ref:`int<class_int>` **round_precision**
  169. +-----------+----------------------------+
  170. | *Default* | ``8`` |
  171. +-----------+----------------------------+
  172. | *Setter* | set_round_precision(value) |
  173. +-----------+----------------------------+
  174. | *Getter* | get_round_precision() |
  175. +-----------+----------------------------+
  176. The smoothness of the rounded joints and caps. Higher values result in smoother corners, but are more demanding to render and update. This is only used if a cap or joint is set as round.
  177. \ **Note:** The default value is tuned for lines with the default :ref:`width<class_Line2D_property_width>`. For thin lines, this value should be reduced to a number between ``2`` and ``4`` to improve performance.
  178. ----
  179. .. _class_Line2D_property_sharp_limit:
  180. - :ref:`float<class_float>` **sharp_limit**
  181. +-----------+------------------------+
  182. | *Default* | ``2.0`` |
  183. +-----------+------------------------+
  184. | *Setter* | set_sharp_limit(value) |
  185. +-----------+------------------------+
  186. | *Getter* | get_sharp_limit() |
  187. +-----------+------------------------+
  188. The direction difference in radians between vector points. This value is only used if :ref:`joint_mode<class_Line2D_property_joint_mode>` is set to :ref:`LINE_JOINT_SHARP<class_Line2D_constant_LINE_JOINT_SHARP>`.
  189. ----
  190. .. _class_Line2D_property_texture:
  191. - :ref:`Texture2D<class_Texture2D>` **texture**
  192. +----------+--------------------+
  193. | *Setter* | set_texture(value) |
  194. +----------+--------------------+
  195. | *Getter* | get_texture() |
  196. +----------+--------------------+
  197. The texture used for the line's texture. Uses ``texture_mode`` for drawing style.
  198. ----
  199. .. _class_Line2D_property_texture_mode:
  200. - :ref:`LineTextureMode<enum_Line2D_LineTextureMode>` **texture_mode**
  201. +-----------+-------------------------+
  202. | *Default* | ``0`` |
  203. +-----------+-------------------------+
  204. | *Setter* | set_texture_mode(value) |
  205. +-----------+-------------------------+
  206. | *Getter* | get_texture_mode() |
  207. +-----------+-------------------------+
  208. The style to render the ``texture`` on the line. Use :ref:`LineTextureMode<enum_Line2D_LineTextureMode>` constants.
  209. ----
  210. .. _class_Line2D_property_width:
  211. - :ref:`float<class_float>` **width**
  212. +-----------+------------------+
  213. | *Default* | ``10.0`` |
  214. +-----------+------------------+
  215. | *Setter* | set_width(value) |
  216. +-----------+------------------+
  217. | *Getter* | get_width() |
  218. +-----------+------------------+
  219. The line's width.
  220. ----
  221. .. _class_Line2D_property_width_curve:
  222. - :ref:`Curve<class_Curve>` **width_curve**
  223. +----------+------------------+
  224. | *Setter* | set_curve(value) |
  225. +----------+------------------+
  226. | *Getter* | get_curve() |
  227. +----------+------------------+
  228. The line's width varies with the curve. The original width is simply multiply by the value of the Curve.
  229. Method Descriptions
  230. -------------------
  231. .. _class_Line2D_method_add_point:
  232. - void **add_point** **(** :ref:`Vector2<class_Vector2>` position, :ref:`int<class_int>` at_position=-1 **)**
  233. Adds a point at the ``position``. Appends the point at the end of the line.
  234. If ``at_position`` is given, the point is inserted before the point number ``at_position``, moving that point (and every point after) after the inserted point. If ``at_position`` is not given, or is an illegal value (``at_position < 0`` or ``at_position >= [method get_point_count]``), the point will be appended at the end of the point list.
  235. ----
  236. .. _class_Line2D_method_clear_points:
  237. - void **clear_points** **(** **)**
  238. Removes all points from the line.
  239. ----
  240. .. _class_Line2D_method_get_point_count:
  241. - :ref:`int<class_int>` **get_point_count** **(** **)** |const|
  242. Returns the Line2D's amount of points.
  243. ----
  244. .. _class_Line2D_method_get_point_position:
  245. - :ref:`Vector2<class_Vector2>` **get_point_position** **(** :ref:`int<class_int>` i **)** |const|
  246. Returns point ``i``'s position.
  247. ----
  248. .. _class_Line2D_method_remove_point:
  249. - void **remove_point** **(** :ref:`int<class_int>` i **)**
  250. Removes the point at index ``i`` from the line.
  251. ----
  252. .. _class_Line2D_method_set_point_position:
  253. - void **set_point_position** **(** :ref:`int<class_int>` i, :ref:`Vector2<class_Vector2>` position **)**
  254. Overwrites the position in point ``i`` with the supplied ``position``.
  255. .. |virtual| replace:: :abbr:`virtual (This method should typically be overridden by the user to have any effect.)`
  256. .. |const| replace:: :abbr:`const (This method has no side effects. It doesn't modify any of the instance's member variables.)`
  257. .. |vararg| replace:: :abbr:`vararg (This method accepts any number of arguments after the ones described here.)`
  258. .. |constructor| replace:: :abbr:`constructor (This method is used to construct a type.)`
  259. .. |static| replace:: :abbr:`static (This method doesn't need an instance to be called, so it can be called directly using the class name.)`
  260. .. |operator| replace:: :abbr:`operator (This method describes a valid operator to use with this type as left-hand operand.)`