Files
godot-docs/classes/class_line2d.rst
2023-05-19 13:35:34 +00:00

513 lines
19 KiB
ReStructuredText

:github_url: hide
.. DO NOT EDIT THIS FILE!!!
.. Generated automatically from Godot engine sources.
.. Generator: https://github.com/godotengine/godot/tree/4.0/doc/tools/make_rst.py.
.. XML source: https://github.com/godotengine/godot/tree/4.0/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 line.
.. rst-class:: classref-introduction-group
Description
-----------
A line through several points in 2D space.
.. rst-class:: classref-introduction-group
Tutorials
---------
- `Matrix Transform Demo <https://godotengine.org/asset-library/asset/584>`__
- `2.5D Demo <https://godotengine.org/asset-library/asset/583>`__
.. 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:`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>` **(** :ref:`Vector2<class_Vector2>` position, :ref:`int<class_int>` index=-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>` **(** :ref:`int<class_int>` index **)** |const| |
+-------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------+
| void | :ref:`remove_point<class_Line2D_method_remove_point>` **(** :ref:`int<class_int>` index **)** |
+-------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------+
| void | :ref:`set_point_position<class_Line2D_method_set_point_position>` **(** :ref:`int<class_int>` index, :ref:`Vector2<class_Vector2>` position **)** |
+-------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------+
.. rst-class:: classref-section-separator
----
.. rst-class:: classref-descriptions-group
Enumerations
------------
.. _enum_Line2D_LineJointMode:
.. rst-class:: classref-enumeration
enum **LineJointMode**:
.. _class_Line2D_constant_LINE_JOINT_SHARP:
.. rst-class:: classref-enumeration-constant
:ref:`LineJointMode<enum_Line2D_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.
.. _class_Line2D_constant_LINE_JOINT_BEVEL:
.. rst-class:: classref-enumeration-constant
:ref:`LineJointMode<enum_Line2D_LineJointMode>` **LINE_JOINT_BEVEL** = ``1``
The line's joints will be bevelled/chamfered.
.. _class_Line2D_constant_LINE_JOINT_ROUND:
.. rst-class:: classref-enumeration-constant
:ref:`LineJointMode<enum_Line2D_LineJointMode>` **LINE_JOINT_ROUND** = ``2``
The line's joints will be rounded.
.. rst-class:: classref-item-separator
----
.. _enum_Line2D_LineCapMode:
.. rst-class:: classref-enumeration
enum **LineCapMode**:
.. _class_Line2D_constant_LINE_CAP_NONE:
.. rst-class:: classref-enumeration-constant
:ref:`LineCapMode<enum_Line2D_LineCapMode>` **LINE_CAP_NONE** = ``0``
Don't draw a 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.
.. _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 circle.
.. rst-class:: classref-item-separator
----
.. _enum_Line2D_LineTextureMode:
.. rst-class:: classref-enumeration
enum **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 it over the whole line.
.. _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 line. :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 line. :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``
.. rst-class:: classref-property-setget
- void **set_antialiased** **(** :ref:`bool<class_bool>` value **)**
- :ref:`bool<class_bool>` **get_antialiased** **(** **)**
If ``true``, the line'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``
.. rst-class:: classref-property-setget
- void **set_begin_cap_mode** **(** :ref:`LineCapMode<enum_Line2D_LineCapMode>` value **)**
- :ref:`LineCapMode<enum_Line2D_LineCapMode>` **get_begin_cap_mode** **(** **)**
Controls the style of the line's first point. Use :ref:`LineCapMode<enum_Line2D_LineCapMode>` constants.
.. 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)``
.. rst-class:: classref-property-setget
- void **set_default_color** **(** :ref:`Color<class_Color>` value **)**
- :ref:`Color<class_Color>` **get_default_color** **(** **)**
The line's color. 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``
.. rst-class:: classref-property-setget
- void **set_end_cap_mode** **(** :ref:`LineCapMode<enum_Line2D_LineCapMode>` value **)**
- :ref:`LineCapMode<enum_Line2D_LineCapMode>` **get_end_cap_mode** **(** **)**
Controls the style of the line's last point. Use :ref:`LineCapMode<enum_Line2D_LineCapMode>` constants.
.. rst-class:: classref-item-separator
----
.. _class_Line2D_property_gradient:
.. rst-class:: classref-property
:ref:`Gradient<class_Gradient>` **gradient**
.. rst-class:: classref-property-setget
- void **set_gradient** **(** :ref:`Gradient<class_Gradient>` value **)**
- :ref:`Gradient<class_Gradient>` **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.
.. rst-class:: classref-item-separator
----
.. _class_Line2D_property_joint_mode:
.. rst-class:: classref-property
:ref:`LineJointMode<enum_Line2D_LineJointMode>` **joint_mode** = ``0``
.. rst-class:: classref-property-setget
- void **set_joint_mode** **(** :ref:`LineJointMode<enum_Line2D_LineJointMode>` value **)**
- :ref:`LineJointMode<enum_Line2D_LineJointMode>` **get_joint_mode** **(** **)**
The style for the points between the start and the end.
.. rst-class:: classref-item-separator
----
.. _class_Line2D_property_points:
.. rst-class:: classref-property
:ref:`PackedVector2Array<class_PackedVector2Array>` **points** = ``PackedVector2Array()``
.. rst-class:: classref-property-setget
- void **set_points** **(** :ref:`PackedVector2Array<class_PackedVector2Array>` value **)**
- :ref:`PackedVector2Array<class_PackedVector2Array>` **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.
.. rst-class:: classref-item-separator
----
.. _class_Line2D_property_round_precision:
.. rst-class:: classref-property
:ref:`int<class_int>` **round_precision** = ``8``
.. rst-class:: classref-property-setget
- void **set_round_precision** **(** :ref:`int<class_int>` value **)**
- :ref:`int<class_int>` **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<class_Line2D_property_width>`. For thin lines, this value should be reduced to a number between ``2`` and ``4`` to improve performance.
.. rst-class:: classref-item-separator
----
.. _class_Line2D_property_sharp_limit:
.. rst-class:: classref-property
:ref:`float<class_float>` **sharp_limit** = ``2.0``
.. rst-class:: classref-property-setget
- void **set_sharp_limit** **(** :ref:`float<class_float>` value **)**
- :ref:`float<class_float>` **get_sharp_limit** **(** **)**
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>`.
.. rst-class:: classref-item-separator
----
.. _class_Line2D_property_texture:
.. rst-class:: classref-property
:ref:`Texture2D<class_Texture2D>` **texture**
.. rst-class:: classref-property-setget
- void **set_texture** **(** :ref:`Texture2D<class_Texture2D>` value **)**
- :ref:`Texture2D<class_Texture2D>` **get_texture** **(** **)**
The texture used for the line's texture. Uses ``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``
.. rst-class:: classref-property-setget
- void **set_texture_mode** **(** :ref:`LineTextureMode<enum_Line2D_LineTextureMode>` value **)**
- :ref:`LineTextureMode<enum_Line2D_LineTextureMode>` **get_texture_mode** **(** **)**
The style to render the ``texture`` on the line. Use :ref:`LineTextureMode<enum_Line2D_LineTextureMode>` constants.
.. rst-class:: classref-item-separator
----
.. _class_Line2D_property_width:
.. rst-class:: classref-property
:ref:`float<class_float>` **width** = ``10.0``
.. rst-class:: classref-property-setget
- void **set_width** **(** :ref:`float<class_float>` value **)**
- :ref:`float<class_float>` **get_width** **(** **)**
The line's width.
.. rst-class:: classref-item-separator
----
.. _class_Line2D_property_width_curve:
.. rst-class:: classref-property
:ref:`Curve<class_Curve>` **width_curve**
.. rst-class:: classref-property-setget
- void **set_curve** **(** :ref:`Curve<class_Curve>` value **)**
- :ref:`Curve<class_Curve>` **get_curve** **(** **)**
The line's width varies with the curve. The original width is simply multiply by the value of the 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** **(** :ref:`Vector2<class_Vector2>` position, :ref:`int<class_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_get_point_count>`.
.. rst-class:: classref-item-separator
----
.. _class_Line2D_method_clear_points:
.. rst-class:: classref-method
void **clear_points** **(** **)**
Removes all points from the line.
.. rst-class:: classref-item-separator
----
.. _class_Line2D_method_get_point_count:
.. rst-class:: classref-method
:ref:`int<class_int>` **get_point_count** **(** **)** |const|
Returns the number of points in the line.
.. rst-class:: classref-item-separator
----
.. _class_Line2D_method_get_point_position:
.. rst-class:: classref-method
:ref:`Vector2<class_Vector2>` **get_point_position** **(** :ref:`int<class_int>` index **)** |const|
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** **(** :ref:`int<class_int>` index **)**
Removes the point at index ``index`` from the line.
.. rst-class:: classref-item-separator
----
.. _class_Line2D_method_set_point_position:
.. rst-class:: classref-method
void **set_point_position** **(** :ref:`int<class_int>` index, :ref:`Vector2<class_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.)`
.. |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.)`