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