: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` **<** :ref:`CanvasItem` **<** :ref:`Node` **<** :ref:`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 `__ - `2.5D Game Demo `__ .. rst-class:: classref-reftable-group Properties ---------- .. table:: :widths: auto +-----------------------------------------------------+---------------------------------------------------------------+--------------------------+ | :ref:`bool` | :ref:`antialiased` | ``false`` | +-----------------------------------------------------+---------------------------------------------------------------+--------------------------+ | :ref:`LineCapMode` | :ref:`begin_cap_mode` | ``0`` | +-----------------------------------------------------+---------------------------------------------------------------+--------------------------+ | :ref:`bool` | :ref:`closed` | ``false`` | +-----------------------------------------------------+---------------------------------------------------------------+--------------------------+ | :ref:`Color` | :ref:`default_color` | ``Color(1, 1, 1, 1)`` | +-----------------------------------------------------+---------------------------------------------------------------+--------------------------+ | :ref:`LineCapMode` | :ref:`end_cap_mode` | ``0`` | +-----------------------------------------------------+---------------------------------------------------------------+--------------------------+ | :ref:`Gradient` | :ref:`gradient` | | +-----------------------------------------------------+---------------------------------------------------------------+--------------------------+ | :ref:`LineJointMode` | :ref:`joint_mode` | ``0`` | +-----------------------------------------------------+---------------------------------------------------------------+--------------------------+ | :ref:`PackedVector2Array` | :ref:`points` | ``PackedVector2Array()`` | +-----------------------------------------------------+---------------------------------------------------------------+--------------------------+ | :ref:`int` | :ref:`round_precision` | ``8`` | +-----------------------------------------------------+---------------------------------------------------------------+--------------------------+ | :ref:`float` | :ref:`sharp_limit` | ``2.0`` | +-----------------------------------------------------+---------------------------------------------------------------+--------------------------+ | :ref:`Texture2D` | :ref:`texture` | | +-----------------------------------------------------+---------------------------------------------------------------+--------------------------+ | :ref:`LineTextureMode` | :ref:`texture_mode` | ``0`` | +-----------------------------------------------------+---------------------------------------------------------------+--------------------------+ | :ref:`float` | :ref:`width` | ``10.0`` | +-----------------------------------------------------+---------------------------------------------------------------+--------------------------+ | :ref:`Curve` | :ref:`width_curve` | | +-----------------------------------------------------+---------------------------------------------------------------+--------------------------+ .. rst-class:: classref-reftable-group Methods ------- .. table:: :widths: auto +-------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------+ | |void| | :ref:`add_point`\ (\ position\: :ref:`Vector2`, index\: :ref:`int` = -1\ ) | +-------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------+ | |void| | :ref:`clear_points`\ (\ ) | +-------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`int` | :ref:`get_point_count`\ (\ ) |const| | +-------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`Vector2` | :ref:`get_point_position`\ (\ index\: :ref:`int`\ ) |const| | +-------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------+ | |void| | :ref:`remove_point`\ (\ index\: :ref:`int`\ ) | +-------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------+ | |void| | :ref:`set_point_position`\ (\ index\: :ref:`int`, position\: :ref:`Vector2`\ ) | +-------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------+ .. rst-class:: classref-section-separator ---- .. rst-class:: classref-descriptions-group Enumerations ------------ .. _enum_Line2D_LineJointMode: .. rst-class:: classref-enumeration enum **LineJointMode**: :ref:`🔗` .. _class_Line2D_constant_LINE_JOINT_SHARP: .. rst-class:: classref-enumeration-constant :ref:`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`), the joint falls back to :ref:`LINE_JOINT_BEVEL` to prevent very long miters. .. _class_Line2D_constant_LINE_JOINT_BEVEL: .. rst-class:: classref-enumeration-constant :ref:`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` **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`. .. rst-class:: classref-item-separator ---- .. _enum_Line2D_LineCapMode: .. rst-class:: classref-enumeration enum **LineCapMode**: :ref:`🔗` .. _class_Line2D_constant_LINE_CAP_NONE: .. rst-class:: classref-enumeration-constant :ref:`LineCapMode` **LINE_CAP_NONE** = ``0`` Draws no line cap. .. _class_Line2D_constant_LINE_CAP_BOX: .. rst-class:: classref-enumeration-constant :ref:`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` **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:`🔗` .. _class_Line2D_constant_LINE_TEXTURE_NONE: .. rst-class:: classref-enumeration-constant :ref:`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` **LINE_TEXTURE_TILE** = ``1`` Tiles the texture over the polyline. :ref:`CanvasItem.texture_repeat` of the **Line2D** node must be :ref:`CanvasItem.TEXTURE_REPEAT_ENABLED` or :ref:`CanvasItem.TEXTURE_REPEAT_MIRROR` for it to work properly. .. _class_Line2D_constant_LINE_TEXTURE_STRETCH: .. rst-class:: classref-enumeration-constant :ref:`LineTextureMode` **LINE_TEXTURE_STRETCH** = ``2`` Stretches the texture across the polyline. :ref:`CanvasItem.texture_repeat` of the **Line2D** node must be :ref:`CanvasItem.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` **antialiased** = ``false`` :ref:`🔗` .. rst-class:: classref-property-setget - |void| **set_antialiased**\ (\ value\: :ref:`bool`\ ) - :ref:`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` **begin_cap_mode** = ``0`` :ref:`🔗` .. rst-class:: classref-property-setget - |void| **set_begin_cap_mode**\ (\ value\: :ref:`LineCapMode`\ ) - :ref:`LineCapMode` **get_begin_cap_mode**\ (\ ) The style of the beginning of the polyline, if :ref:`closed` is ``false``. .. rst-class:: classref-item-separator ---- .. _class_Line2D_property_closed: .. rst-class:: classref-property :ref:`bool` **closed** = ``false`` :ref:`🔗` .. rst-class:: classref-property-setget - |void| **set_closed**\ (\ value\: :ref:`bool`\ ) - :ref:`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` is provided. \ **Note:** The joint between the closing segment and the first segment is drawn first and it samples the :ref:`gradient` and the :ref:`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` **default_color** = ``Color(1, 1, 1, 1)`` :ref:`🔗` .. rst-class:: classref-property-setget - |void| **set_default_color**\ (\ value\: :ref:`Color`\ ) - :ref:`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` **end_cap_mode** = ``0`` :ref:`🔗` .. rst-class:: classref-property-setget - |void| **set_end_cap_mode**\ (\ value\: :ref:`LineCapMode`\ ) - :ref:`LineCapMode` **get_end_cap_mode**\ (\ ) The style of the end of the polyline, if :ref:`closed` is ``false``. .. rst-class:: classref-item-separator ---- .. _class_Line2D_property_gradient: .. rst-class:: classref-property :ref:`Gradient` **gradient** :ref:`🔗` .. rst-class:: classref-property-setget - |void| **set_gradient**\ (\ value\: :ref:`Gradient`\ ) - :ref:`Gradient` **get_gradient**\ (\ ) The gradient is drawn through the whole line from start to finish. The :ref:`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` **joint_mode** = ``0`` :ref:`🔗` .. rst-class:: classref-property-setget - |void| **set_joint_mode**\ (\ value\: :ref:`LineJointMode`\ ) - :ref:`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` **points** = ``PackedVector2Array()`` :ref:`🔗` .. rst-class:: classref-property-setget - |void| **set_points**\ (\ value\: :ref:`PackedVector2Array`\ ) - :ref:`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` for more details. .. rst-class:: classref-item-separator ---- .. _class_Line2D_property_round_precision: .. rst-class:: classref-property :ref:`int` **round_precision** = ``8`` :ref:`🔗` .. rst-class:: classref-property-setget - |void| **set_round_precision**\ (\ value\: :ref:`int`\ ) - :ref:`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` **sharp_limit** = ``2.0`` :ref:`🔗` .. rst-class:: classref-property-setget - |void| **set_sharp_limit**\ (\ value\: :ref:`float`\ ) - :ref:`float` **get_sharp_limit**\ (\ ) Determines the miter limit of the polyline. Normally, when :ref:`joint_mode` is set to :ref:`LINE_JOINT_SHARP`, sharp angles fall back to using the logic of :ref:`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` **texture** :ref:`🔗` .. rst-class:: classref-property-setget - |void| **set_texture**\ (\ value\: :ref:`Texture2D`\ ) - :ref:`Texture2D` **get_texture**\ (\ ) The texture used for the polyline. Uses :ref:`texture_mode` for drawing style. .. rst-class:: classref-item-separator ---- .. _class_Line2D_property_texture_mode: .. rst-class:: classref-property :ref:`LineTextureMode` **texture_mode** = ``0`` :ref:`🔗` .. rst-class:: classref-property-setget - |void| **set_texture_mode**\ (\ value\: :ref:`LineTextureMode`\ ) - :ref:`LineTextureMode` **get_texture_mode**\ (\ ) The style to render the :ref:`texture` of the polyline. .. rst-class:: classref-item-separator ---- .. _class_Line2D_property_width: .. rst-class:: classref-property :ref:`float` **width** = ``10.0`` :ref:`🔗` .. rst-class:: classref-property-setget - |void| **set_width**\ (\ value\: :ref:`float`\ ) - :ref:`float` **get_width**\ (\ ) The polyline's width. .. rst-class:: classref-item-separator ---- .. _class_Line2D_property_width_curve: .. rst-class:: classref-property :ref:`Curve` **width_curve** :ref:`🔗` .. rst-class:: classref-property-setget - |void| **set_curve**\ (\ value\: :ref:`Curve`\ ) - :ref:`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`. .. 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`, index\: :ref:`int` = -1\ ) :ref:`🔗` 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()`. .. rst-class:: classref-item-separator ---- .. _class_Line2D_method_clear_points: .. rst-class:: classref-method |void| **clear_points**\ (\ ) :ref:`🔗` 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` **get_point_count**\ (\ ) |const| :ref:`🔗` 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` **get_point_position**\ (\ index\: :ref:`int`\ ) |const| :ref:`🔗` 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`\ ) :ref:`🔗` 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`, position\: :ref:`Vector2`\ ) :ref:`🔗` 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.)`