class_line2d.rst 19 KB

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