class_line2d.rst 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514
  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/3.6/doc/tools/make_rst.py.
  5. .. XML source: https://github.com/godotengine/godot/tree/3.6/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. Supports varying width and color over the line's length, texturing, and several cap/joint types.
  15. \ **Note:** By default, Godot can only draw up to 4,096 polygon points at a time. To increase this limit, open the Project Settings and increase :ref:`ProjectSettings.rendering/limits/buffers/canvas_polygon_buffer_size_kb<class_ProjectSettings_property_rendering/limits/buffers/canvas_polygon_buffer_size_kb>` and :ref:`ProjectSettings.rendering/limits/buffers/canvas_polygon_index_buffer_size_kb<class_ProjectSettings_property_rendering/limits/buffers/canvas_polygon_index_buffer_size_kb>`.
  16. .. rst-class:: classref-introduction-group
  17. Tutorials
  18. ---------
  19. - `Matrix Transform Demo <https://godotengine.org/asset-library/asset/584>`__
  20. - `2.5D Demo <https://godotengine.org/asset-library/asset/583>`__
  21. .. rst-class:: classref-reftable-group
  22. Properties
  23. ----------
  24. .. table::
  25. :widths: auto
  26. +-----------------------------------------------------+---------------------------------------------------------------+-----------------------------+
  27. | :ref:`bool<class_bool>` | :ref:`antialiased<class_Line2D_property_antialiased>` | ``false`` |
  28. +-----------------------------------------------------+---------------------------------------------------------------+-----------------------------+
  29. | :ref:`LineCapMode<enum_Line2D_LineCapMode>` | :ref:`begin_cap_mode<class_Line2D_property_begin_cap_mode>` | ``0`` |
  30. +-----------------------------------------------------+---------------------------------------------------------------+-----------------------------+
  31. | :ref:`Color<class_Color>` | :ref:`default_color<class_Line2D_property_default_color>` | ``Color( 0.4, 0.5, 1, 1 )`` |
  32. +-----------------------------------------------------+---------------------------------------------------------------+-----------------------------+
  33. | :ref:`LineCapMode<enum_Line2D_LineCapMode>` | :ref:`end_cap_mode<class_Line2D_property_end_cap_mode>` | ``0`` |
  34. +-----------------------------------------------------+---------------------------------------------------------------+-----------------------------+
  35. | :ref:`Gradient<class_Gradient>` | :ref:`gradient<class_Line2D_property_gradient>` | |
  36. +-----------------------------------------------------+---------------------------------------------------------------+-----------------------------+
  37. | :ref:`LineJointMode<enum_Line2D_LineJointMode>` | :ref:`joint_mode<class_Line2D_property_joint_mode>` | ``0`` |
  38. +-----------------------------------------------------+---------------------------------------------------------------+-----------------------------+
  39. | :ref:`PoolVector2Array<class_PoolVector2Array>` | :ref:`points<class_Line2D_property_points>` | ``PoolVector2Array( )`` |
  40. +-----------------------------------------------------+---------------------------------------------------------------+-----------------------------+
  41. | :ref:`int<class_int>` | :ref:`round_precision<class_Line2D_property_round_precision>` | ``8`` |
  42. +-----------------------------------------------------+---------------------------------------------------------------+-----------------------------+
  43. | :ref:`float<class_float>` | :ref:`sharp_limit<class_Line2D_property_sharp_limit>` | ``2.0`` |
  44. +-----------------------------------------------------+---------------------------------------------------------------+-----------------------------+
  45. | :ref:`Texture<class_Texture>` | :ref:`texture<class_Line2D_property_texture>` | |
  46. +-----------------------------------------------------+---------------------------------------------------------------+-----------------------------+
  47. | :ref:`LineTextureMode<enum_Line2D_LineTextureMode>` | :ref:`texture_mode<class_Line2D_property_texture_mode>` | ``0`` |
  48. +-----------------------------------------------------+---------------------------------------------------------------+-----------------------------+
  49. | :ref:`float<class_float>` | :ref:`width<class_Line2D_property_width>` | ``10.0`` |
  50. +-----------------------------------------------------+---------------------------------------------------------------+-----------------------------+
  51. | :ref:`Curve<class_Curve>` | :ref:`width_curve<class_Line2D_property_width_curve>` | |
  52. +-----------------------------------------------------+---------------------------------------------------------------+-----------------------------+
  53. .. rst-class:: classref-reftable-group
  54. Methods
  55. -------
  56. .. table::
  57. :widths: auto
  58. +-------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------+
  59. | void | :ref:`add_point<class_Line2D_method_add_point>` **(** :ref:`Vector2<class_Vector2>` position, :ref:`int<class_int>` index=-1 **)** |
  60. +-------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------+
  61. | void | :ref:`clear_points<class_Line2D_method_clear_points>` **(** **)** |
  62. +-------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------+
  63. | :ref:`int<class_int>` | :ref:`get_point_count<class_Line2D_method_get_point_count>` **(** **)** |const| |
  64. +-------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------+
  65. | :ref:`Vector2<class_Vector2>` | :ref:`get_point_position<class_Line2D_method_get_point_position>` **(** :ref:`int<class_int>` index **)** |const| |
  66. +-------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------+
  67. | void | :ref:`remove_point<class_Line2D_method_remove_point>` **(** :ref:`int<class_int>` index **)** |
  68. +-------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------+
  69. | void | :ref:`set_point_position<class_Line2D_method_set_point_position>` **(** :ref:`int<class_int>` index, :ref:`Vector2<class_Vector2>` position **)** |
  70. +-------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------+
  71. .. rst-class:: classref-section-separator
  72. ----
  73. .. rst-class:: classref-descriptions-group
  74. Enumerations
  75. ------------
  76. .. _enum_Line2D_LineJointMode:
  77. .. rst-class:: classref-enumeration
  78. enum **LineJointMode**:
  79. .. _class_Line2D_constant_LINE_JOINT_SHARP:
  80. .. rst-class:: classref-enumeration-constant
  81. :ref:`LineJointMode<enum_Line2D_LineJointMode>` **LINE_JOINT_SHARP** = ``0``
  82. The line's joints will be pointy. If ``sharp_limit`` is greater than the rotation of a joint, it becomes a bevel joint instead.
  83. .. _class_Line2D_constant_LINE_JOINT_BEVEL:
  84. .. rst-class:: classref-enumeration-constant
  85. :ref:`LineJointMode<enum_Line2D_LineJointMode>` **LINE_JOINT_BEVEL** = ``1``
  86. The line's joints will be bevelled/chamfered.
  87. .. _class_Line2D_constant_LINE_JOINT_ROUND:
  88. .. rst-class:: classref-enumeration-constant
  89. :ref:`LineJointMode<enum_Line2D_LineJointMode>` **LINE_JOINT_ROUND** = ``2``
  90. The line's joints will be rounded.
  91. .. rst-class:: classref-item-separator
  92. ----
  93. .. _enum_Line2D_LineCapMode:
  94. .. rst-class:: classref-enumeration
  95. enum **LineCapMode**:
  96. .. _class_Line2D_constant_LINE_CAP_NONE:
  97. .. rst-class:: classref-enumeration-constant
  98. :ref:`LineCapMode<enum_Line2D_LineCapMode>` **LINE_CAP_NONE** = ``0``
  99. Don't draw a line cap.
  100. .. _class_Line2D_constant_LINE_CAP_BOX:
  101. .. rst-class:: classref-enumeration-constant
  102. :ref:`LineCapMode<enum_Line2D_LineCapMode>` **LINE_CAP_BOX** = ``1``
  103. Draws the line cap as a box.
  104. .. _class_Line2D_constant_LINE_CAP_ROUND:
  105. .. rst-class:: classref-enumeration-constant
  106. :ref:`LineCapMode<enum_Line2D_LineCapMode>` **LINE_CAP_ROUND** = ``2``
  107. Draws the line cap as a circle.
  108. .. rst-class:: classref-item-separator
  109. ----
  110. .. _enum_Line2D_LineTextureMode:
  111. .. rst-class:: classref-enumeration
  112. enum **LineTextureMode**:
  113. .. _class_Line2D_constant_LINE_TEXTURE_NONE:
  114. .. rst-class:: classref-enumeration-constant
  115. :ref:`LineTextureMode<enum_Line2D_LineTextureMode>` **LINE_TEXTURE_NONE** = ``0``
  116. Takes the left pixels of the texture and renders it over the whole line.
  117. .. _class_Line2D_constant_LINE_TEXTURE_TILE:
  118. .. rst-class:: classref-enumeration-constant
  119. :ref:`LineTextureMode<enum_Line2D_LineTextureMode>` **LINE_TEXTURE_TILE** = ``1``
  120. Tiles the texture over the line. The texture must be imported with **Repeat** enabled for it to work properly.
  121. .. _class_Line2D_constant_LINE_TEXTURE_STRETCH:
  122. .. rst-class:: classref-enumeration-constant
  123. :ref:`LineTextureMode<enum_Line2D_LineTextureMode>` **LINE_TEXTURE_STRETCH** = ``2``
  124. Stretches the texture across the line. Import the texture with **Repeat** disabled for best results.
  125. .. rst-class:: classref-section-separator
  126. ----
  127. .. rst-class:: classref-descriptions-group
  128. Property Descriptions
  129. ---------------------
  130. .. _class_Line2D_property_antialiased:
  131. .. rst-class:: classref-property
  132. :ref:`bool<class_bool>` **antialiased** = ``false``
  133. .. rst-class:: classref-property-setget
  134. - void **set_antialiased** **(** :ref:`bool<class_bool>` value **)**
  135. - :ref:`bool<class_bool>` **get_antialiased** **(** **)**
  136. If ``true``, the line's border will attempt to perform antialiasing by drawing thin OpenGL smooth lines on the line's edges.
  137. \ **Note:** Line2D is not accelerated by batching if :ref:`antialiased<class_Line2D_property_antialiased>` is ``true``.
  138. \ **Note:** Due to how it works, built-in antialiasing will not look correct for translucent lines and may not work on certain platforms. As a workaround, install the `Antialiased Line2D <https://github.com/godot-extended-libraries/godot-antialiased-line2d>`__ add-on then create an AntialiasedLine2D node. That node relies on a texture with custom mipmaps to perform antialiasing. 2D batching is also still supported with those antialiased lines.
  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. Controls the style of the line's first point. 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( 0.4, 0.5, 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 line's color. 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. Controls the style of the line's last point. 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 for the points between the start and the end.
  184. .. rst-class:: classref-item-separator
  185. ----
  186. .. _class_Line2D_property_points:
  187. .. rst-class:: classref-property
  188. :ref:`PoolVector2Array<class_PoolVector2Array>` **points** = ``PoolVector2Array( )``
  189. .. rst-class:: classref-property-setget
  190. - void **set_points** **(** :ref:`PoolVector2Array<class_PoolVector2Array>` value **)**
  191. - :ref:`PoolVector2Array<class_PoolVector2Array>` **get_points** **(** **)**
  192. The points that form the lines. The line is drawn between every point set in this array. Points are interpreted as local vectors.
  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 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.
  202. \ **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.
  203. .. rst-class:: classref-item-separator
  204. ----
  205. .. _class_Line2D_property_sharp_limit:
  206. .. rst-class:: classref-property
  207. :ref:`float<class_float>` **sharp_limit** = ``2.0``
  208. .. rst-class:: classref-property-setget
  209. - void **set_sharp_limit** **(** :ref:`float<class_float>` value **)**
  210. - :ref:`float<class_float>` **get_sharp_limit** **(** **)**
  211. 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>`.
  212. .. rst-class:: classref-item-separator
  213. ----
  214. .. _class_Line2D_property_texture:
  215. .. rst-class:: classref-property
  216. :ref:`Texture<class_Texture>` **texture**
  217. .. rst-class:: classref-property-setget
  218. - void **set_texture** **(** :ref:`Texture<class_Texture>` value **)**
  219. - :ref:`Texture<class_Texture>` **get_texture** **(** **)**
  220. The texture used for the line's texture. Uses ``texture_mode`` for drawing style.
  221. .. rst-class:: classref-item-separator
  222. ----
  223. .. _class_Line2D_property_texture_mode:
  224. .. rst-class:: classref-property
  225. :ref:`LineTextureMode<enum_Line2D_LineTextureMode>` **texture_mode** = ``0``
  226. .. rst-class:: classref-property-setget
  227. - void **set_texture_mode** **(** :ref:`LineTextureMode<enum_Line2D_LineTextureMode>` value **)**
  228. - :ref:`LineTextureMode<enum_Line2D_LineTextureMode>` **get_texture_mode** **(** **)**
  229. The style to render the ``texture`` on the line. Use :ref:`LineTextureMode<enum_Line2D_LineTextureMode>` constants.
  230. .. rst-class:: classref-item-separator
  231. ----
  232. .. _class_Line2D_property_width:
  233. .. rst-class:: classref-property
  234. :ref:`float<class_float>` **width** = ``10.0``
  235. .. rst-class:: classref-property-setget
  236. - void **set_width** **(** :ref:`float<class_float>` value **)**
  237. - :ref:`float<class_float>` **get_width** **(** **)**
  238. The line's width.
  239. .. rst-class:: classref-item-separator
  240. ----
  241. .. _class_Line2D_property_width_curve:
  242. .. rst-class:: classref-property
  243. :ref:`Curve<class_Curve>` **width_curve**
  244. .. rst-class:: classref-property-setget
  245. - void **set_curve** **(** :ref:`Curve<class_Curve>` value **)**
  246. - :ref:`Curve<class_Curve>` **get_curve** **(** **)**
  247. The line's width varies with the curve. The original width is simply multiply by the value of the Curve.
  248. .. rst-class:: classref-section-separator
  249. ----
  250. .. rst-class:: classref-descriptions-group
  251. Method Descriptions
  252. -------------------
  253. .. _class_Line2D_method_add_point:
  254. .. rst-class:: classref-method
  255. void **add_point** **(** :ref:`Vector2<class_Vector2>` position, :ref:`int<class_int>` index=-1 **)**
  256. 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.
  257. 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>`.
  258. .. rst-class:: classref-item-separator
  259. ----
  260. .. _class_Line2D_method_clear_points:
  261. .. rst-class:: classref-method
  262. void **clear_points** **(** **)**
  263. Removes all points from the line.
  264. .. rst-class:: classref-item-separator
  265. ----
  266. .. _class_Line2D_method_get_point_count:
  267. .. rst-class:: classref-method
  268. :ref:`int<class_int>` **get_point_count** **(** **)** |const|
  269. Returns the amount of points in the line.
  270. .. rst-class:: classref-item-separator
  271. ----
  272. .. _class_Line2D_method_get_point_position:
  273. .. rst-class:: classref-method
  274. :ref:`Vector2<class_Vector2>` **get_point_position** **(** :ref:`int<class_int>` index **)** |const|
  275. Returns the position of the point at index ``index``.
  276. .. rst-class:: classref-item-separator
  277. ----
  278. .. _class_Line2D_method_remove_point:
  279. .. rst-class:: classref-method
  280. void **remove_point** **(** :ref:`int<class_int>` index **)**
  281. Removes the point at index ``index`` from the line.
  282. .. rst-class:: classref-item-separator
  283. ----
  284. .. _class_Line2D_method_set_point_position:
  285. .. rst-class:: classref-method
  286. void **set_point_position** **(** :ref:`int<class_int>` index, :ref:`Vector2<class_Vector2>` position **)**
  287. Overwrites the position of the point at index ``index`` with the supplied ``position``.
  288. .. |virtual| replace:: :abbr:`virtual (This method should typically be overridden by the user to have any effect.)`
  289. .. |const| replace:: :abbr:`const (This method has no side effects. It doesn't modify any of the instance's member variables.)`
  290. .. |vararg| replace:: :abbr:`vararg (This method accepts any number of arguments after the ones described here.)`
  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.)`