class_line2d.rst 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515
  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/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 polyline that can optionally be textured.
  11. .. rst-class:: classref-introduction-group
  12. Description
  13. -----------
  14. This node draws a 2D polyline, i.e. a shape consisting of several points connected by segments. **Line2D** is not a mathematical polyline, i.e. the segments are not infinitely thin. It is intended for rendering and it can be colored and optionally textured.
  15. \ **Warning:** Certain configurations may be impossible to draw nicely, such as very sharp angles. In these situations, the node uses fallback drawing logic to look decent.
  16. \ **Note:** **Line2D** is drawn using a 2D mesh.
  17. .. rst-class:: classref-introduction-group
  18. Tutorials
  19. ---------
  20. - `Matrix Transform Demo <https://godotengine.org/asset-library/asset/584>`__
  21. - `2.5D Demo <https://godotengine.org/asset-library/asset/583>`__
  22. .. rst-class:: classref-reftable-group
  23. Properties
  24. ----------
  25. .. table::
  26. :widths: auto
  27. +-----------------------------------------------------+---------------------------------------------------------------+--------------------------+
  28. | :ref:`bool<class_bool>` | :ref:`antialiased<class_Line2D_property_antialiased>` | ``false`` |
  29. +-----------------------------------------------------+---------------------------------------------------------------+--------------------------+
  30. | :ref:`LineCapMode<enum_Line2D_LineCapMode>` | :ref:`begin_cap_mode<class_Line2D_property_begin_cap_mode>` | ``0`` |
  31. +-----------------------------------------------------+---------------------------------------------------------------+--------------------------+
  32. | :ref:`Color<class_Color>` | :ref:`default_color<class_Line2D_property_default_color>` | ``Color(1, 1, 1, 1)`` |
  33. +-----------------------------------------------------+---------------------------------------------------------------+--------------------------+
  34. | :ref:`LineCapMode<enum_Line2D_LineCapMode>` | :ref:`end_cap_mode<class_Line2D_property_end_cap_mode>` | ``0`` |
  35. +-----------------------------------------------------+---------------------------------------------------------------+--------------------------+
  36. | :ref:`Gradient<class_Gradient>` | :ref:`gradient<class_Line2D_property_gradient>` | |
  37. +-----------------------------------------------------+---------------------------------------------------------------+--------------------------+
  38. | :ref:`LineJointMode<enum_Line2D_LineJointMode>` | :ref:`joint_mode<class_Line2D_property_joint_mode>` | ``0`` |
  39. +-----------------------------------------------------+---------------------------------------------------------------+--------------------------+
  40. | :ref:`PackedVector2Array<class_PackedVector2Array>` | :ref:`points<class_Line2D_property_points>` | ``PackedVector2Array()`` |
  41. +-----------------------------------------------------+---------------------------------------------------------------+--------------------------+
  42. | :ref:`int<class_int>` | :ref:`round_precision<class_Line2D_property_round_precision>` | ``8`` |
  43. +-----------------------------------------------------+---------------------------------------------------------------+--------------------------+
  44. | :ref:`float<class_float>` | :ref:`sharp_limit<class_Line2D_property_sharp_limit>` | ``2.0`` |
  45. +-----------------------------------------------------+---------------------------------------------------------------+--------------------------+
  46. | :ref:`Texture2D<class_Texture2D>` | :ref:`texture<class_Line2D_property_texture>` | |
  47. +-----------------------------------------------------+---------------------------------------------------------------+--------------------------+
  48. | :ref:`LineTextureMode<enum_Line2D_LineTextureMode>` | :ref:`texture_mode<class_Line2D_property_texture_mode>` | ``0`` |
  49. +-----------------------------------------------------+---------------------------------------------------------------+--------------------------+
  50. | :ref:`float<class_float>` | :ref:`width<class_Line2D_property_width>` | ``10.0`` |
  51. +-----------------------------------------------------+---------------------------------------------------------------+--------------------------+
  52. | :ref:`Curve<class_Curve>` | :ref:`width_curve<class_Line2D_property_width_curve>` | |
  53. +-----------------------------------------------------+---------------------------------------------------------------+--------------------------+
  54. .. rst-class:: classref-reftable-group
  55. Methods
  56. -------
  57. .. table::
  58. :widths: auto
  59. +-------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------+
  60. | void | :ref:`add_point<class_Line2D_method_add_point>` **(** :ref:`Vector2<class_Vector2>` position, :ref:`int<class_int>` index=-1 **)** |
  61. +-------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------+
  62. | void | :ref:`clear_points<class_Line2D_method_clear_points>` **(** **)** |
  63. +-------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------+
  64. | :ref:`int<class_int>` | :ref:`get_point_count<class_Line2D_method_get_point_count>` **(** **)** |const| |
  65. +-------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------+
  66. | :ref:`Vector2<class_Vector2>` | :ref:`get_point_position<class_Line2D_method_get_point_position>` **(** :ref:`int<class_int>` index **)** |const| |
  67. +-------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------+
  68. | void | :ref:`remove_point<class_Line2D_method_remove_point>` **(** :ref:`int<class_int>` index **)** |
  69. +-------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------+
  70. | void | :ref:`set_point_position<class_Line2D_method_set_point_position>` **(** :ref:`int<class_int>` index, :ref:`Vector2<class_Vector2>` position **)** |
  71. +-------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------+
  72. .. rst-class:: classref-section-separator
  73. ----
  74. .. rst-class:: classref-descriptions-group
  75. Enumerations
  76. ------------
  77. .. _enum_Line2D_LineJointMode:
  78. .. rst-class:: classref-enumeration
  79. enum **LineJointMode**:
  80. .. _class_Line2D_constant_LINE_JOINT_SHARP:
  81. .. rst-class:: classref-enumeration-constant
  82. :ref:`LineJointMode<enum_Line2D_LineJointMode>` **LINE_JOINT_SHARP** = ``0``
  83. Makes the polyline's joints pointy, connecting the sides of the two segments by extending them until they intersect. If the rotation of a joint is too big (based on :ref:`sharp_limit<class_Line2D_property_sharp_limit>`), the joint falls back to :ref:`LINE_JOINT_BEVEL<class_Line2D_constant_LINE_JOINT_BEVEL>` to prevent very long miters.
  84. .. _class_Line2D_constant_LINE_JOINT_BEVEL:
  85. .. rst-class:: classref-enumeration-constant
  86. :ref:`LineJointMode<enum_Line2D_LineJointMode>` **LINE_JOINT_BEVEL** = ``1``
  87. Makes the polyline's joints bevelled/chamfered, connecting the sides of the two segments with a simple line.
  88. .. _class_Line2D_constant_LINE_JOINT_ROUND:
  89. .. rst-class:: classref-enumeration-constant
  90. :ref:`LineJointMode<enum_Line2D_LineJointMode>` **LINE_JOINT_ROUND** = ``2``
  91. Makes the polyline's joints rounded, connecting the sides of the two segments with an arc. The detail of this arc depends on :ref:`round_precision<class_Line2D_property_round_precision>`.
  92. .. rst-class:: classref-item-separator
  93. ----
  94. .. _enum_Line2D_LineCapMode:
  95. .. rst-class:: classref-enumeration
  96. enum **LineCapMode**:
  97. .. _class_Line2D_constant_LINE_CAP_NONE:
  98. .. rst-class:: classref-enumeration-constant
  99. :ref:`LineCapMode<enum_Line2D_LineCapMode>` **LINE_CAP_NONE** = ``0``
  100. Draws no line cap.
  101. .. _class_Line2D_constant_LINE_CAP_BOX:
  102. .. rst-class:: classref-enumeration-constant
  103. :ref:`LineCapMode<enum_Line2D_LineCapMode>` **LINE_CAP_BOX** = ``1``
  104. Draws the line cap as a box, slightly extending the first/last segment.
  105. .. _class_Line2D_constant_LINE_CAP_ROUND:
  106. .. rst-class:: classref-enumeration-constant
  107. :ref:`LineCapMode<enum_Line2D_LineCapMode>` **LINE_CAP_ROUND** = ``2``
  108. Draws the line cap as a semicircle attached to the first/last segment.
  109. .. rst-class:: classref-item-separator
  110. ----
  111. .. _enum_Line2D_LineTextureMode:
  112. .. rst-class:: classref-enumeration
  113. enum **LineTextureMode**:
  114. .. _class_Line2D_constant_LINE_TEXTURE_NONE:
  115. .. rst-class:: classref-enumeration-constant
  116. :ref:`LineTextureMode<enum_Line2D_LineTextureMode>` **LINE_TEXTURE_NONE** = ``0``
  117. Takes the left pixels of the texture and renders them over the whole polyline.
  118. .. _class_Line2D_constant_LINE_TEXTURE_TILE:
  119. .. rst-class:: classref-enumeration-constant
  120. :ref:`LineTextureMode<enum_Line2D_LineTextureMode>` **LINE_TEXTURE_TILE** = ``1``
  121. Tiles the texture over the polyline. :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.
  122. .. _class_Line2D_constant_LINE_TEXTURE_STRETCH:
  123. .. rst-class:: classref-enumeration-constant
  124. :ref:`LineTextureMode<enum_Line2D_LineTextureMode>` **LINE_TEXTURE_STRETCH** = ``2``
  125. Stretches the texture across the polyline. :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.
  126. .. rst-class:: classref-section-separator
  127. ----
  128. .. rst-class:: classref-descriptions-group
  129. Property Descriptions
  130. ---------------------
  131. .. _class_Line2D_property_antialiased:
  132. .. rst-class:: classref-property
  133. :ref:`bool<class_bool>` **antialiased** = ``false``
  134. .. rst-class:: classref-property-setget
  135. - void **set_antialiased** **(** :ref:`bool<class_bool>` value **)**
  136. - :ref:`bool<class_bool>` **get_antialiased** **(** **)**
  137. If ``true``, the polyline's border will be anti-aliased.
  138. \ **Note:** **Line2D** is not accelerated by batching when being anti-aliased.
  139. .. rst-class:: classref-item-separator
  140. ----
  141. .. _class_Line2D_property_begin_cap_mode:
  142. .. rst-class:: classref-property
  143. :ref:`LineCapMode<enum_Line2D_LineCapMode>` **begin_cap_mode** = ``0``
  144. .. rst-class:: classref-property-setget
  145. - void **set_begin_cap_mode** **(** :ref:`LineCapMode<enum_Line2D_LineCapMode>` value **)**
  146. - :ref:`LineCapMode<enum_Line2D_LineCapMode>` **get_begin_cap_mode** **(** **)**
  147. The style of the beginning of the polyline. Use :ref:`LineCapMode<enum_Line2D_LineCapMode>` constants.
  148. .. rst-class:: classref-item-separator
  149. ----
  150. .. _class_Line2D_property_default_color:
  151. .. rst-class:: classref-property
  152. :ref:`Color<class_Color>` **default_color** = ``Color(1, 1, 1, 1)``
  153. .. rst-class:: classref-property-setget
  154. - void **set_default_color** **(** :ref:`Color<class_Color>` value **)**
  155. - :ref:`Color<class_Color>` **get_default_color** **(** **)**
  156. The color of the polyline. Will not be used if a gradient is set.
  157. .. rst-class:: classref-item-separator
  158. ----
  159. .. _class_Line2D_property_end_cap_mode:
  160. .. rst-class:: classref-property
  161. :ref:`LineCapMode<enum_Line2D_LineCapMode>` **end_cap_mode** = ``0``
  162. .. rst-class:: classref-property-setget
  163. - void **set_end_cap_mode** **(** :ref:`LineCapMode<enum_Line2D_LineCapMode>` value **)**
  164. - :ref:`LineCapMode<enum_Line2D_LineCapMode>` **get_end_cap_mode** **(** **)**
  165. The style of the end of the polyline. Use :ref:`LineCapMode<enum_Line2D_LineCapMode>` constants.
  166. .. rst-class:: classref-item-separator
  167. ----
  168. .. _class_Line2D_property_gradient:
  169. .. rst-class:: classref-property
  170. :ref:`Gradient<class_Gradient>` **gradient**
  171. .. rst-class:: classref-property-setget
  172. - void **set_gradient** **(** :ref:`Gradient<class_Gradient>` value **)**
  173. - :ref:`Gradient<class_Gradient>` **get_gradient** **(** **)**
  174. The gradient is drawn through the whole line from start to finish. The default color will not be used if a gradient is set.
  175. .. rst-class:: classref-item-separator
  176. ----
  177. .. _class_Line2D_property_joint_mode:
  178. .. rst-class:: classref-property
  179. :ref:`LineJointMode<enum_Line2D_LineJointMode>` **joint_mode** = ``0``
  180. .. rst-class:: classref-property-setget
  181. - void **set_joint_mode** **(** :ref:`LineJointMode<enum_Line2D_LineJointMode>` value **)**
  182. - :ref:`LineJointMode<enum_Line2D_LineJointMode>` **get_joint_mode** **(** **)**
  183. The style of the connections between segments of the polyline. Use :ref:`LineJointMode<enum_Line2D_LineJointMode>` constants.
  184. .. rst-class:: classref-item-separator
  185. ----
  186. .. _class_Line2D_property_points:
  187. .. rst-class:: classref-property
  188. :ref:`PackedVector2Array<class_PackedVector2Array>` **points** = ``PackedVector2Array()``
  189. .. rst-class:: classref-property-setget
  190. - void **set_points** **(** :ref:`PackedVector2Array<class_PackedVector2Array>` value **)**
  191. - :ref:`PackedVector2Array<class_PackedVector2Array>` **get_points** **(** **)**
  192. The points of the polyline, interpreted in local 2D coordinates. Segments are drawn between the adjacent points in this array.
  193. .. rst-class:: classref-item-separator
  194. ----
  195. .. _class_Line2D_property_round_precision:
  196. .. rst-class:: classref-property
  197. :ref:`int<class_int>` **round_precision** = ``8``
  198. .. rst-class:: classref-property-setget
  199. - void **set_round_precision** **(** :ref:`int<class_int>` value **)**
  200. - :ref:`int<class_int>` **get_round_precision** **(** **)**
  201. The smoothness used for rounded joints and caps. Higher values result in smoother corners, but are more demanding to render and update.
  202. .. rst-class:: classref-item-separator
  203. ----
  204. .. _class_Line2D_property_sharp_limit:
  205. .. rst-class:: classref-property
  206. :ref:`float<class_float>` **sharp_limit** = ``2.0``
  207. .. rst-class:: classref-property-setget
  208. - void **set_sharp_limit** **(** :ref:`float<class_float>` value **)**
  209. - :ref:`float<class_float>` **get_sharp_limit** **(** **)**
  210. Determines the miter limit of the polyline. Normally, when :ref:`joint_mode<class_Line2D_property_joint_mode>` is set to :ref:`LINE_JOINT_SHARP<class_Line2D_constant_LINE_JOINT_SHARP>`, sharp angles fall back to using the logic of :ref:`LINE_JOINT_BEVEL<class_Line2D_constant_LINE_JOINT_BEVEL>` joints to prevent very long miters. Higher values of this property mean that the fallback to a bevel joint will happen at sharper angles.
  211. .. rst-class:: classref-item-separator
  212. ----
  213. .. _class_Line2D_property_texture:
  214. .. rst-class:: classref-property
  215. :ref:`Texture2D<class_Texture2D>` **texture**
  216. .. rst-class:: classref-property-setget
  217. - void **set_texture** **(** :ref:`Texture2D<class_Texture2D>` value **)**
  218. - :ref:`Texture2D<class_Texture2D>` **get_texture** **(** **)**
  219. The texture used for the polyline. Uses ``texture_mode`` for drawing style.
  220. .. rst-class:: classref-item-separator
  221. ----
  222. .. _class_Line2D_property_texture_mode:
  223. .. rst-class:: classref-property
  224. :ref:`LineTextureMode<enum_Line2D_LineTextureMode>` **texture_mode** = ``0``
  225. .. rst-class:: classref-property-setget
  226. - void **set_texture_mode** **(** :ref:`LineTextureMode<enum_Line2D_LineTextureMode>` value **)**
  227. - :ref:`LineTextureMode<enum_Line2D_LineTextureMode>` **get_texture_mode** **(** **)**
  228. The style to render the :ref:`texture<class_Line2D_property_texture>` of the polyline. Use :ref:`LineTextureMode<enum_Line2D_LineTextureMode>` constants.
  229. .. rst-class:: classref-item-separator
  230. ----
  231. .. _class_Line2D_property_width:
  232. .. rst-class:: classref-property
  233. :ref:`float<class_float>` **width** = ``10.0``
  234. .. rst-class:: classref-property-setget
  235. - void **set_width** **(** :ref:`float<class_float>` value **)**
  236. - :ref:`float<class_float>` **get_width** **(** **)**
  237. The polyline's width
  238. .. rst-class:: classref-item-separator
  239. ----
  240. .. _class_Line2D_property_width_curve:
  241. .. rst-class:: classref-property
  242. :ref:`Curve<class_Curve>` **width_curve**
  243. .. rst-class:: classref-property-setget
  244. - void **set_curve** **(** :ref:`Curve<class_Curve>` value **)**
  245. - :ref:`Curve<class_Curve>` **get_curve** **(** **)**
  246. The polyline's width curve. The width of the polyline over its length will be equivalent to the value of the width curve over its domain.
  247. .. rst-class:: classref-section-separator
  248. ----
  249. .. rst-class:: classref-descriptions-group
  250. Method Descriptions
  251. -------------------
  252. .. _class_Line2D_method_add_point:
  253. .. rst-class:: classref-method
  254. void **add_point** **(** :ref:`Vector2<class_Vector2>` position, :ref:`int<class_int>` index=-1 **)**
  255. Adds a point with the specified ``position`` relative to the polyline's own position. If no ``index`` is provided, the new point will be added to the end of the points array.
  256. If ``index`` is given, the new point is inserted before the existing point identified by index ``index``. The indices of the points after the new point get increased by 1. The provided ``index`` must not exceed the number of existing points in the polyline. See :ref:`get_point_count<class_Line2D_method_get_point_count>`.
  257. .. rst-class:: classref-item-separator
  258. ----
  259. .. _class_Line2D_method_clear_points:
  260. .. rst-class:: classref-method
  261. void **clear_points** **(** **)**
  262. Removes all points from the polyline, making it empty.
  263. .. rst-class:: classref-item-separator
  264. ----
  265. .. _class_Line2D_method_get_point_count:
  266. .. rst-class:: classref-method
  267. :ref:`int<class_int>` **get_point_count** **(** **)** |const|
  268. Returns the number of points in the polyline.
  269. .. rst-class:: classref-item-separator
  270. ----
  271. .. _class_Line2D_method_get_point_position:
  272. .. rst-class:: classref-method
  273. :ref:`Vector2<class_Vector2>` **get_point_position** **(** :ref:`int<class_int>` index **)** |const|
  274. Returns the position of the point at index ``index``.
  275. .. rst-class:: classref-item-separator
  276. ----
  277. .. _class_Line2D_method_remove_point:
  278. .. rst-class:: classref-method
  279. void **remove_point** **(** :ref:`int<class_int>` index **)**
  280. Removes the point at index ``index`` from the polyline.
  281. .. rst-class:: classref-item-separator
  282. ----
  283. .. _class_Line2D_method_set_point_position:
  284. .. rst-class:: classref-method
  285. void **set_point_position** **(** :ref:`int<class_int>` index, :ref:`Vector2<class_Vector2>` position **)**
  286. Overwrites the position of the point at the given ``index`` with the supplied ``position``.
  287. .. |virtual| replace:: :abbr:`virtual (This method should typically be overridden by the user to have any effect.)`
  288. .. |const| replace:: :abbr:`const (This method has no side effects. It doesn't modify any of the instance's member variables.)`
  289. .. |vararg| replace:: :abbr:`vararg (This method accepts any number of arguments after the ones described here.)`
  290. .. |constructor| replace:: :abbr:`constructor (This method is used to construct a type.)`
  291. .. |static| replace:: :abbr:`static (This method doesn't need an instance to be called, so it can be called directly using the class name.)`
  292. .. |operator| replace:: :abbr:`operator (This method describes a valid operator to use with this type as left-hand operand.)`
  293. .. |bitfield| replace:: :abbr:`BitField (This value is an integer composed as a bitmask of the following flags.)`