:github_url: hide .. DO NOT EDIT THIS FILE!!! .. Generated automatically from Godot engine sources. .. Generator: https://github.com/godotengine/godot/tree/3.5/doc/tools/make_rst.py. .. XML source: https://github.com/godotengine/godot/tree/3.5/doc/classes/Line2D.xml. .. _class_Line2D: Line2D ====== **Inherits:** :ref:`Node2D` **<** :ref:`CanvasItem` **<** :ref:`Node` **<** :ref:`Object` A 2D line. Description ----------- A line through several points in 2D space. Supports varying width and color over the line's length, texturing, and several cap/joint types. \ **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` and :ref:`ProjectSettings.rendering/limits/buffers/canvas_polygon_index_buffer_size_kb`. Tutorials --------- - `Matrix Transform Demo `__ - `2.5D Demo `__ Properties ---------- +-----------------------------------------------------+---------------------------------------------------------------+-----------------------------+ | :ref:`bool` | :ref:`antialiased` | ``false`` | +-----------------------------------------------------+---------------------------------------------------------------+-----------------------------+ | :ref:`LineCapMode` | :ref:`begin_cap_mode` | ``0`` | +-----------------------------------------------------+---------------------------------------------------------------+-----------------------------+ | :ref:`Color` | :ref:`default_color` | ``Color( 0.4, 0.5, 1, 1 )`` | +-----------------------------------------------------+---------------------------------------------------------------+-----------------------------+ | :ref:`LineCapMode` | :ref:`end_cap_mode` | ``0`` | +-----------------------------------------------------+---------------------------------------------------------------+-----------------------------+ | :ref:`Gradient` | :ref:`gradient` | | +-----------------------------------------------------+---------------------------------------------------------------+-----------------------------+ | :ref:`LineJointMode` | :ref:`joint_mode` | ``0`` | +-----------------------------------------------------+---------------------------------------------------------------+-----------------------------+ | :ref:`PoolVector2Array` | :ref:`points` | ``PoolVector2Array( )`` | +-----------------------------------------------------+---------------------------------------------------------------+-----------------------------+ | :ref:`int` | :ref:`round_precision` | ``8`` | +-----------------------------------------------------+---------------------------------------------------------------+-----------------------------+ | :ref:`float` | :ref:`sharp_limit` | ``2.0`` | +-----------------------------------------------------+---------------------------------------------------------------+-----------------------------+ | :ref:`Texture` | :ref:`texture` | | +-----------------------------------------------------+---------------------------------------------------------------+-----------------------------+ | :ref:`LineTextureMode` | :ref:`texture_mode` | ``0`` | +-----------------------------------------------------+---------------------------------------------------------------+-----------------------------+ | :ref:`float` | :ref:`width` | ``10.0`` | +-----------------------------------------------------+---------------------------------------------------------------+-----------------------------+ | :ref:`Curve` | :ref:`width_curve` | | +-----------------------------------------------------+---------------------------------------------------------------+-----------------------------+ Methods ------- +-------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------+ | void | :ref:`add_point` **(** :ref:`Vector2` position, :ref:`int` index=-1 **)** | +-------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------+ | void | :ref:`clear_points` **(** **)** | +-------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`int` | :ref:`get_point_count` **(** **)** |const| | +-------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`Vector2` | :ref:`get_point_position` **(** :ref:`int` index **)** |const| | +-------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------+ | void | :ref:`remove_point` **(** :ref:`int` index **)** | +-------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------+ | void | :ref:`set_point_position` **(** :ref:`int` index, :ref:`Vector2` position **)** | +-------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------+ Enumerations ------------ .. _enum_Line2D_LineJointMode: .. _class_Line2D_constant_LINE_JOINT_SHARP: .. _class_Line2D_constant_LINE_JOINT_BEVEL: .. _class_Line2D_constant_LINE_JOINT_ROUND: enum **LineJointMode**: - **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. - **LINE_JOINT_BEVEL** = **1** --- The line's joints will be bevelled/chamfered. - **LINE_JOINT_ROUND** = **2** --- The line's joints will be rounded. ---- .. _enum_Line2D_LineCapMode: .. _class_Line2D_constant_LINE_CAP_NONE: .. _class_Line2D_constant_LINE_CAP_BOX: .. _class_Line2D_constant_LINE_CAP_ROUND: enum **LineCapMode**: - **LINE_CAP_NONE** = **0** --- Don't draw a line cap. - **LINE_CAP_BOX** = **1** --- Draws the line cap as a box. - **LINE_CAP_ROUND** = **2** --- Draws the line cap as a circle. ---- .. _enum_Line2D_LineTextureMode: .. _class_Line2D_constant_LINE_TEXTURE_NONE: .. _class_Line2D_constant_LINE_TEXTURE_TILE: .. _class_Line2D_constant_LINE_TEXTURE_STRETCH: enum **LineTextureMode**: - **LINE_TEXTURE_NONE** = **0** --- Takes the left pixels of the texture and renders it over the whole line. - **LINE_TEXTURE_TILE** = **1** --- Tiles the texture over the line. The texture must be imported with **Repeat** enabled for it to work properly. - **LINE_TEXTURE_STRETCH** = **2** --- Stretches the texture across the line. Import the texture with **Repeat** disabled for best results. Property Descriptions --------------------- .. _class_Line2D_property_antialiased: - :ref:`bool` **antialiased** +-----------+------------------------+ | *Default* | ``false`` | +-----------+------------------------+ | *Setter* | set_antialiased(value) | +-----------+------------------------+ | *Getter* | get_antialiased() | +-----------+------------------------+ If ``true``, the line's border will attempt to perform antialiasing by drawing thin OpenGL smooth lines on the line's edges. \ **Note:** Line2D is not accelerated by batching if :ref:`antialiased` is ``true``. \ **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 `__ 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. ---- .. _class_Line2D_property_begin_cap_mode: - :ref:`LineCapMode` **begin_cap_mode** +-----------+---------------------------+ | *Default* | ``0`` | +-----------+---------------------------+ | *Setter* | set_begin_cap_mode(value) | +-----------+---------------------------+ | *Getter* | get_begin_cap_mode() | +-----------+---------------------------+ Controls the style of the line's first point. Use :ref:`LineCapMode` constants. ---- .. _class_Line2D_property_default_color: - :ref:`Color` **default_color** +-----------+-----------------------------+ | *Default* | ``Color( 0.4, 0.5, 1, 1 )`` | +-----------+-----------------------------+ | *Setter* | set_default_color(value) | +-----------+-----------------------------+ | *Getter* | get_default_color() | +-----------+-----------------------------+ The line's color. Will not be used if a gradient is set. ---- .. _class_Line2D_property_end_cap_mode: - :ref:`LineCapMode` **end_cap_mode** +-----------+-------------------------+ | *Default* | ``0`` | +-----------+-------------------------+ | *Setter* | set_end_cap_mode(value) | +-----------+-------------------------+ | *Getter* | get_end_cap_mode() | +-----------+-------------------------+ Controls the style of the line's last point. Use :ref:`LineCapMode` constants. ---- .. _class_Line2D_property_gradient: - :ref:`Gradient` **gradient** +----------+---------------------+ | *Setter* | set_gradient(value) | +----------+---------------------+ | *Getter* | get_gradient() | +----------+---------------------+ The gradient is drawn through the whole line from start to finish. The default color will not be used if a gradient is set. ---- .. _class_Line2D_property_joint_mode: - :ref:`LineJointMode` **joint_mode** +-----------+-----------------------+ | *Default* | ``0`` | +-----------+-----------------------+ | *Setter* | set_joint_mode(value) | +-----------+-----------------------+ | *Getter* | get_joint_mode() | +-----------+-----------------------+ The style for the points between the start and the end. ---- .. _class_Line2D_property_points: - :ref:`PoolVector2Array` **points** +-----------+--------------------------+ | *Default* | ``PoolVector2Array( )`` | +-----------+--------------------------+ | *Setter* | set_points(value) | +-----------+--------------------------+ | *Getter* | get_points() | +-----------+--------------------------+ The points that form the lines. The line is drawn between every point set in this array. Points are interpreted as local vectors. ---- .. _class_Line2D_property_round_precision: - :ref:`int` **round_precision** +-----------+----------------------------+ | *Default* | ``8`` | +-----------+----------------------------+ | *Setter* | set_round_precision(value) | +-----------+----------------------------+ | *Getter* | get_round_precision() | +-----------+----------------------------+ 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. \ **Note:** The default value is tuned for lines with the default :ref:`width`. For thin lines, this value should be reduced to a number between ``2`` and ``4`` to improve performance. ---- .. _class_Line2D_property_sharp_limit: - :ref:`float` **sharp_limit** +-----------+------------------------+ | *Default* | ``2.0`` | +-----------+------------------------+ | *Setter* | set_sharp_limit(value) | +-----------+------------------------+ | *Getter* | get_sharp_limit() | +-----------+------------------------+ The direction difference in radians between vector points. This value is only used if :ref:`joint_mode` is set to :ref:`LINE_JOINT_SHARP`. ---- .. _class_Line2D_property_texture: - :ref:`Texture` **texture** +----------+--------------------+ | *Setter* | set_texture(value) | +----------+--------------------+ | *Getter* | get_texture() | +----------+--------------------+ The texture used for the line's texture. Uses ``texture_mode`` for drawing style. ---- .. _class_Line2D_property_texture_mode: - :ref:`LineTextureMode` **texture_mode** +-----------+-------------------------+ | *Default* | ``0`` | +-----------+-------------------------+ | *Setter* | set_texture_mode(value) | +-----------+-------------------------+ | *Getter* | get_texture_mode() | +-----------+-------------------------+ The style to render the ``texture`` on the line. Use :ref:`LineTextureMode` constants. ---- .. _class_Line2D_property_width: - :ref:`float` **width** +-----------+------------------+ | *Default* | ``10.0`` | +-----------+------------------+ | *Setter* | set_width(value) | +-----------+------------------+ | *Getter* | get_width() | +-----------+------------------+ The line's width. ---- .. _class_Line2D_property_width_curve: - :ref:`Curve` **width_curve** +----------+------------------+ | *Setter* | set_curve(value) | +----------+------------------+ | *Getter* | get_curve() | +----------+------------------+ The line's width varies with the curve. The original width is simply multiply by the value of the Curve. Method Descriptions ------------------- .. _class_Line2D_method_add_point: - void **add_point** **(** :ref:`Vector2` position, :ref:`int` index=-1 **)** 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. 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_clear_points: - void **clear_points** **(** **)** Removes all points from the line. ---- .. _class_Line2D_method_get_point_count: - :ref:`int` **get_point_count** **(** **)** |const| Returns the amount of points in the line. ---- .. _class_Line2D_method_get_point_position: - :ref:`Vector2` **get_point_position** **(** :ref:`int` index **)** |const| Returns the position of the point at index ``index``. ---- .. _class_Line2D_method_remove_point: - void **remove_point** **(** :ref:`int` index **)** Removes the point at index ``index`` from the line. ---- .. _class_Line2D_method_set_point_position: - void **set_point_position** **(** :ref:`int` index, :ref:`Vector2` position **)** Overwrites the position of the point at index ``index`` with the supplied ``position``. .. |virtual| replace:: :abbr:`virtual (This method should typically be overridden by the user to have any effect.)` .. |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.)`