Files
godot-docs/classes/class_line2d.rst
2025-06-07 03:33:02 +00:00

543 lines
23 KiB
ReStructuredText

:github_url: hide
.. DO NOT EDIT THIS FILE!!!
.. Generated automatically from Godot engine sources.
.. Generator: https://github.com/godotengine/godot/tree/master/doc/tools/make_rst.py.
.. XML source: https://github.com/godotengine/godot/tree/master/doc/classes/Line2D.xml.
.. _class_Line2D:
Line2D
======
**Inherits:** :ref:`Node2D<class_Node2D>` **<** :ref:`CanvasItem<class_CanvasItem>` **<** :ref:`Node<class_Node>` **<** :ref:`Object<class_Object>`
A 2D polyline that can optionally be textured.
.. rst-class:: classref-introduction-group
Description
-----------
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.
\ **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.
\ **Note:** **Line2D** is drawn using a 2D mesh.
.. rst-class:: classref-introduction-group
Tutorials
---------
- `Matrix Transform Demo <https://godotengine.org/asset-library/asset/2787>`__
- `2.5D Game Demo <https://godotengine.org/asset-library/asset/2783>`__
.. rst-class:: classref-reftable-group
Properties
----------
.. table::
:widths: auto
+-----------------------------------------------------+---------------------------------------------------------------+--------------------------+
| :ref:`bool<class_bool>` | :ref:`antialiased<class_Line2D_property_antialiased>` | ``false`` |
+-----------------------------------------------------+---------------------------------------------------------------+--------------------------+
| :ref:`LineCapMode<enum_Line2D_LineCapMode>` | :ref:`begin_cap_mode<class_Line2D_property_begin_cap_mode>` | ``0`` |
+-----------------------------------------------------+---------------------------------------------------------------+--------------------------+
| :ref:`bool<class_bool>` | :ref:`closed<class_Line2D_property_closed>` | ``false`` |
+-----------------------------------------------------+---------------------------------------------------------------+--------------------------+
| :ref:`Color<class_Color>` | :ref:`default_color<class_Line2D_property_default_color>` | ``Color(1, 1, 1, 1)`` |
+-----------------------------------------------------+---------------------------------------------------------------+--------------------------+
| :ref:`LineCapMode<enum_Line2D_LineCapMode>` | :ref:`end_cap_mode<class_Line2D_property_end_cap_mode>` | ``0`` |
+-----------------------------------------------------+---------------------------------------------------------------+--------------------------+
| :ref:`Gradient<class_Gradient>` | :ref:`gradient<class_Line2D_property_gradient>` | |
+-----------------------------------------------------+---------------------------------------------------------------+--------------------------+
| :ref:`LineJointMode<enum_Line2D_LineJointMode>` | :ref:`joint_mode<class_Line2D_property_joint_mode>` | ``0`` |
+-----------------------------------------------------+---------------------------------------------------------------+--------------------------+
| :ref:`PackedVector2Array<class_PackedVector2Array>` | :ref:`points<class_Line2D_property_points>` | ``PackedVector2Array()`` |
+-----------------------------------------------------+---------------------------------------------------------------+--------------------------+
| :ref:`int<class_int>` | :ref:`round_precision<class_Line2D_property_round_precision>` | ``8`` |
+-----------------------------------------------------+---------------------------------------------------------------+--------------------------+
| :ref:`float<class_float>` | :ref:`sharp_limit<class_Line2D_property_sharp_limit>` | ``2.0`` |
+-----------------------------------------------------+---------------------------------------------------------------+--------------------------+
| :ref:`Texture2D<class_Texture2D>` | :ref:`texture<class_Line2D_property_texture>` | |
+-----------------------------------------------------+---------------------------------------------------------------+--------------------------+
| :ref:`LineTextureMode<enum_Line2D_LineTextureMode>` | :ref:`texture_mode<class_Line2D_property_texture_mode>` | ``0`` |
+-----------------------------------------------------+---------------------------------------------------------------+--------------------------+
| :ref:`float<class_float>` | :ref:`width<class_Line2D_property_width>` | ``10.0`` |
+-----------------------------------------------------+---------------------------------------------------------------+--------------------------+
| :ref:`Curve<class_Curve>` | :ref:`width_curve<class_Line2D_property_width_curve>` | |
+-----------------------------------------------------+---------------------------------------------------------------+--------------------------+
.. rst-class:: classref-reftable-group
Methods
-------
.. table::
:widths: auto
+-------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------+
| |void| | :ref:`add_point<class_Line2D_method_add_point>`\ (\ position\: :ref:`Vector2<class_Vector2>`, index\: :ref:`int<class_int>` = -1\ ) |
+-------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------+
| |void| | :ref:`clear_points<class_Line2D_method_clear_points>`\ (\ ) |
+-------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------+
| :ref:`int<class_int>` | :ref:`get_point_count<class_Line2D_method_get_point_count>`\ (\ ) |const| |
+-------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------+
| :ref:`Vector2<class_Vector2>` | :ref:`get_point_position<class_Line2D_method_get_point_position>`\ (\ index\: :ref:`int<class_int>`\ ) |const| |
+-------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------+
| |void| | :ref:`remove_point<class_Line2D_method_remove_point>`\ (\ index\: :ref:`int<class_int>`\ ) |
+-------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------+
| |void| | :ref:`set_point_position<class_Line2D_method_set_point_position>`\ (\ index\: :ref:`int<class_int>`, position\: :ref:`Vector2<class_Vector2>`\ ) |
+-------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------+
.. rst-class:: classref-section-separator
----
.. rst-class:: classref-descriptions-group
Enumerations
------------
.. _enum_Line2D_LineJointMode:
.. rst-class:: classref-enumeration
enum **LineJointMode**: :ref:`🔗<enum_Line2D_LineJointMode>`
.. _class_Line2D_constant_LINE_JOINT_SHARP:
.. rst-class:: classref-enumeration-constant
:ref:`LineJointMode<enum_Line2D_LineJointMode>` **LINE_JOINT_SHARP** = ``0``
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.
.. _class_Line2D_constant_LINE_JOINT_BEVEL:
.. rst-class:: classref-enumeration-constant
:ref:`LineJointMode<enum_Line2D_LineJointMode>` **LINE_JOINT_BEVEL** = ``1``
Makes the polyline's joints bevelled/chamfered, connecting the sides of the two segments with a simple line.
.. _class_Line2D_constant_LINE_JOINT_ROUND:
.. rst-class:: classref-enumeration-constant
:ref:`LineJointMode<enum_Line2D_LineJointMode>` **LINE_JOINT_ROUND** = ``2``
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>`.
.. rst-class:: classref-item-separator
----
.. _enum_Line2D_LineCapMode:
.. rst-class:: classref-enumeration
enum **LineCapMode**: :ref:`🔗<enum_Line2D_LineCapMode>`
.. _class_Line2D_constant_LINE_CAP_NONE:
.. rst-class:: classref-enumeration-constant
:ref:`LineCapMode<enum_Line2D_LineCapMode>` **LINE_CAP_NONE** = ``0``
Draws no line cap.
.. _class_Line2D_constant_LINE_CAP_BOX:
.. rst-class:: classref-enumeration-constant
:ref:`LineCapMode<enum_Line2D_LineCapMode>` **LINE_CAP_BOX** = ``1``
Draws the line cap as a box, slightly extending the first/last segment.
.. _class_Line2D_constant_LINE_CAP_ROUND:
.. rst-class:: classref-enumeration-constant
:ref:`LineCapMode<enum_Line2D_LineCapMode>` **LINE_CAP_ROUND** = ``2``
Draws the line cap as a semicircle attached to the first/last segment.
.. rst-class:: classref-item-separator
----
.. _enum_Line2D_LineTextureMode:
.. rst-class:: classref-enumeration
enum **LineTextureMode**: :ref:`🔗<enum_Line2D_LineTextureMode>`
.. _class_Line2D_constant_LINE_TEXTURE_NONE:
.. rst-class:: classref-enumeration-constant
:ref:`LineTextureMode<enum_Line2D_LineTextureMode>` **LINE_TEXTURE_NONE** = ``0``
Takes the left pixels of the texture and renders them over the whole polyline.
.. _class_Line2D_constant_LINE_TEXTURE_TILE:
.. rst-class:: classref-enumeration-constant
:ref:`LineTextureMode<enum_Line2D_LineTextureMode>` **LINE_TEXTURE_TILE** = ``1``
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.
.. _class_Line2D_constant_LINE_TEXTURE_STRETCH:
.. rst-class:: classref-enumeration-constant
:ref:`LineTextureMode<enum_Line2D_LineTextureMode>` **LINE_TEXTURE_STRETCH** = ``2``
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.
.. rst-class:: classref-section-separator
----
.. rst-class:: classref-descriptions-group
Property Descriptions
---------------------
.. _class_Line2D_property_antialiased:
.. rst-class:: classref-property
:ref:`bool<class_bool>` **antialiased** = ``false`` :ref:`🔗<class_Line2D_property_antialiased>`
.. rst-class:: classref-property-setget
- |void| **set_antialiased**\ (\ value\: :ref:`bool<class_bool>`\ )
- :ref:`bool<class_bool>` **get_antialiased**\ (\ )
If ``true``, the polyline's border will be anti-aliased.
\ **Note:** **Line2D** is not accelerated by batching when being anti-aliased.
.. rst-class:: classref-item-separator
----
.. _class_Line2D_property_begin_cap_mode:
.. rst-class:: classref-property
:ref:`LineCapMode<enum_Line2D_LineCapMode>` **begin_cap_mode** = ``0`` :ref:`🔗<class_Line2D_property_begin_cap_mode>`
.. rst-class:: classref-property-setget
- |void| **set_begin_cap_mode**\ (\ value\: :ref:`LineCapMode<enum_Line2D_LineCapMode>`\ )
- :ref:`LineCapMode<enum_Line2D_LineCapMode>` **get_begin_cap_mode**\ (\ )
The style of the beginning of the polyline, if :ref:`closed<class_Line2D_property_closed>` is ``false``.
.. rst-class:: classref-item-separator
----
.. _class_Line2D_property_closed:
.. rst-class:: classref-property
:ref:`bool<class_bool>` **closed** = ``false`` :ref:`🔗<class_Line2D_property_closed>`
.. rst-class:: classref-property-setget
- |void| **set_closed**\ (\ value\: :ref:`bool<class_bool>`\ )
- :ref:`bool<class_bool>` **is_closed**\ (\ )
If ``true`` and the polyline has more than 2 points, the last point and the first one will be connected by a segment.
\ **Note:** The shape of the closing segment is not guaranteed to be seamless if a :ref:`width_curve<class_Line2D_property_width_curve>` is provided.
\ **Note:** The joint between the closing segment and the first segment is drawn first and it samples the :ref:`gradient<class_Line2D_property_gradient>` and the :ref:`width_curve<class_Line2D_property_width_curve>` at the beginning. This is an implementation detail that might change in a future version.
.. rst-class:: classref-item-separator
----
.. _class_Line2D_property_default_color:
.. rst-class:: classref-property
:ref:`Color<class_Color>` **default_color** = ``Color(1, 1, 1, 1)`` :ref:`🔗<class_Line2D_property_default_color>`
.. rst-class:: classref-property-setget
- |void| **set_default_color**\ (\ value\: :ref:`Color<class_Color>`\ )
- :ref:`Color<class_Color>` **get_default_color**\ (\ )
The color of the polyline. Will not be used if a gradient is set.
.. rst-class:: classref-item-separator
----
.. _class_Line2D_property_end_cap_mode:
.. rst-class:: classref-property
:ref:`LineCapMode<enum_Line2D_LineCapMode>` **end_cap_mode** = ``0`` :ref:`🔗<class_Line2D_property_end_cap_mode>`
.. rst-class:: classref-property-setget
- |void| **set_end_cap_mode**\ (\ value\: :ref:`LineCapMode<enum_Line2D_LineCapMode>`\ )
- :ref:`LineCapMode<enum_Line2D_LineCapMode>` **get_end_cap_mode**\ (\ )
The style of the end of the polyline, if :ref:`closed<class_Line2D_property_closed>` is ``false``.
.. rst-class:: classref-item-separator
----
.. _class_Line2D_property_gradient:
.. rst-class:: classref-property
:ref:`Gradient<class_Gradient>` **gradient** :ref:`🔗<class_Line2D_property_gradient>`
.. rst-class:: classref-property-setget
- |void| **set_gradient**\ (\ value\: :ref:`Gradient<class_Gradient>`\ )
- :ref:`Gradient<class_Gradient>` **get_gradient**\ (\ )
The gradient is drawn through the whole line from start to finish. The :ref:`default_color<class_Line2D_property_default_color>` will not be used if this property is set.
.. rst-class:: classref-item-separator
----
.. _class_Line2D_property_joint_mode:
.. rst-class:: classref-property
:ref:`LineJointMode<enum_Line2D_LineJointMode>` **joint_mode** = ``0`` :ref:`🔗<class_Line2D_property_joint_mode>`
.. rst-class:: classref-property-setget
- |void| **set_joint_mode**\ (\ value\: :ref:`LineJointMode<enum_Line2D_LineJointMode>`\ )
- :ref:`LineJointMode<enum_Line2D_LineJointMode>` **get_joint_mode**\ (\ )
The style of the connections between segments of the polyline.
.. rst-class:: classref-item-separator
----
.. _class_Line2D_property_points:
.. rst-class:: classref-property
:ref:`PackedVector2Array<class_PackedVector2Array>` **points** = ``PackedVector2Array()`` :ref:`🔗<class_Line2D_property_points>`
.. rst-class:: classref-property-setget
- |void| **set_points**\ (\ value\: :ref:`PackedVector2Array<class_PackedVector2Array>`\ )
- :ref:`PackedVector2Array<class_PackedVector2Array>` **get_points**\ (\ )
The points of the polyline, interpreted in local 2D coordinates. Segments are drawn between the adjacent points in this array.
**Note:** The returned array is *copied* and any changes to it will not update the original property value. See :ref:`PackedVector2Array<class_PackedVector2Array>` for more details.
.. rst-class:: classref-item-separator
----
.. _class_Line2D_property_round_precision:
.. rst-class:: classref-property
:ref:`int<class_int>` **round_precision** = ``8`` :ref:`🔗<class_Line2D_property_round_precision>`
.. rst-class:: classref-property-setget
- |void| **set_round_precision**\ (\ value\: :ref:`int<class_int>`\ )
- :ref:`int<class_int>` **get_round_precision**\ (\ )
The smoothness used for rounded joints and caps. Higher values result in smoother corners, but are more demanding to render and update.
.. rst-class:: classref-item-separator
----
.. _class_Line2D_property_sharp_limit:
.. rst-class:: classref-property
:ref:`float<class_float>` **sharp_limit** = ``2.0`` :ref:`🔗<class_Line2D_property_sharp_limit>`
.. rst-class:: classref-property-setget
- |void| **set_sharp_limit**\ (\ value\: :ref:`float<class_float>`\ )
- :ref:`float<class_float>` **get_sharp_limit**\ (\ )
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.
.. rst-class:: classref-item-separator
----
.. _class_Line2D_property_texture:
.. rst-class:: classref-property
:ref:`Texture2D<class_Texture2D>` **texture** :ref:`🔗<class_Line2D_property_texture>`
.. rst-class:: classref-property-setget
- |void| **set_texture**\ (\ value\: :ref:`Texture2D<class_Texture2D>`\ )
- :ref:`Texture2D<class_Texture2D>` **get_texture**\ (\ )
The texture used for the polyline. Uses :ref:`texture_mode<class_Line2D_property_texture_mode>` for drawing style.
.. rst-class:: classref-item-separator
----
.. _class_Line2D_property_texture_mode:
.. rst-class:: classref-property
:ref:`LineTextureMode<enum_Line2D_LineTextureMode>` **texture_mode** = ``0`` :ref:`🔗<class_Line2D_property_texture_mode>`
.. rst-class:: classref-property-setget
- |void| **set_texture_mode**\ (\ value\: :ref:`LineTextureMode<enum_Line2D_LineTextureMode>`\ )
- :ref:`LineTextureMode<enum_Line2D_LineTextureMode>` **get_texture_mode**\ (\ )
The style to render the :ref:`texture<class_Line2D_property_texture>` of the polyline.
.. rst-class:: classref-item-separator
----
.. _class_Line2D_property_width:
.. rst-class:: classref-property
:ref:`float<class_float>` **width** = ``10.0`` :ref:`🔗<class_Line2D_property_width>`
.. rst-class:: classref-property-setget
- |void| **set_width**\ (\ value\: :ref:`float<class_float>`\ )
- :ref:`float<class_float>` **get_width**\ (\ )
The polyline's width.
.. rst-class:: classref-item-separator
----
.. _class_Line2D_property_width_curve:
.. rst-class:: classref-property
:ref:`Curve<class_Curve>` **width_curve** :ref:`🔗<class_Line2D_property_width_curve>`
.. rst-class:: classref-property-setget
- |void| **set_curve**\ (\ value\: :ref:`Curve<class_Curve>`\ )
- :ref:`Curve<class_Curve>` **get_curve**\ (\ )
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. The width curve should be a unit :ref:`Curve<class_Curve>`.
.. rst-class:: classref-section-separator
----
.. rst-class:: classref-descriptions-group
Method Descriptions
-------------------
.. _class_Line2D_method_add_point:
.. rst-class:: classref-method
|void| **add_point**\ (\ position\: :ref:`Vector2<class_Vector2>`, index\: :ref:`int<class_int>` = -1\ ) :ref:`🔗<class_Line2D_method_add_point>`
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.
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>`.
.. rst-class:: classref-item-separator
----
.. _class_Line2D_method_clear_points:
.. rst-class:: classref-method
|void| **clear_points**\ (\ ) :ref:`🔗<class_Line2D_method_clear_points>`
Removes all points from the polyline, making it empty.
.. rst-class:: classref-item-separator
----
.. _class_Line2D_method_get_point_count:
.. rst-class:: classref-method
:ref:`int<class_int>` **get_point_count**\ (\ ) |const| :ref:`🔗<class_Line2D_method_get_point_count>`
Returns the number of points in the polyline.
.. rst-class:: classref-item-separator
----
.. _class_Line2D_method_get_point_position:
.. rst-class:: classref-method
:ref:`Vector2<class_Vector2>` **get_point_position**\ (\ index\: :ref:`int<class_int>`\ ) |const| :ref:`🔗<class_Line2D_method_get_point_position>`
Returns the position of the point at index ``index``.
.. rst-class:: classref-item-separator
----
.. _class_Line2D_method_remove_point:
.. rst-class:: classref-method
|void| **remove_point**\ (\ index\: :ref:`int<class_int>`\ ) :ref:`🔗<class_Line2D_method_remove_point>`
Removes the point at index ``index`` from the polyline.
.. rst-class:: classref-item-separator
----
.. _class_Line2D_method_set_point_position:
.. rst-class:: classref-method
|void| **set_point_position**\ (\ index\: :ref:`int<class_int>`, position\: :ref:`Vector2<class_Vector2>`\ ) :ref:`🔗<class_Line2D_method_set_point_position>`
Overwrites the position of the point at the given ``index`` with the supplied ``position``.
.. |virtual| replace:: :abbr:`virtual (This method should typically be overridden by the user to have any effect.)`
.. |required| replace:: :abbr:`required (This method is required to be overridden when extending its base class.)`
.. |const| replace:: :abbr:`const (This method has no side effects. It doesn't modify any of the instance's member variables.)`
.. |vararg| replace:: :abbr:`vararg (This method accepts any number of arguments after the ones described here.)`
.. |constructor| replace:: :abbr:`constructor (This method is used to construct a type.)`
.. |static| replace:: :abbr:`static (This method doesn't need an instance to be called, so it can be called directly using the class name.)`
.. |operator| replace:: :abbr:`operator (This method describes a valid operator to use with this type as left-hand operand.)`
.. |bitfield| replace:: :abbr:`BitField (This value is an integer composed as a bitmask of the following flags.)`
.. |void| replace:: :abbr:`void (No return value.)`