Line2D

    A 2D line.

    A line through several points in 2D space.

    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 and ProjectSettings.rendering/limits/buffers/canvas_polygon_index_buffer_size_kb.

    Tutorials

    Methods

    void ( Vector2 position, at_position=-1 )
    voidclear_points ( )
    get_point_count ( ) const
    get_point_position ( i ) const
    voidremove_point ( i )
    voidset_point_position ( i, Vector2 position )

    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.

    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 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

    • antialiased
    Default
    Setterset_antialiased(value)
    Getterget_antialiased()

    If true, the line’s border will be anti-aliased.


    Default0
    Setterset_begin_cap_mode(value)
    Getterget_begin_cap_mode()

    Controls the style of the line’s first point. Use constants.


    DefaultColor( 0.4, 0.5, 1, 1 )
    Setterset_default_color(value)
    Getterget_default_color()

    • end_cap_mode

    Controls the style of the line’s last point. Use LineCapMode constants.


    • gradient
    Setterset_gradient(value)
    Getterget_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.


    Default0
    Setterset_joint_mode(value)
    Getterget_joint_mode()

    The style for the points between the start and the end.


    DefaultPoolVector2Array(  )
    Setterset_points(value)
    Getterget_points()

    The points that form the lines. The line is drawn between every point set in this array. Points are interpreted as local vectors.


    • round_precision
    Default8
    Setterset_round_precision(value)
    Getterget_round_precision()

    The smoothness of the rounded joints and caps. This is only used if a cap or joint is set as round.


    The direction difference in radians between vector points. This value is only used if joint mode is set to .


    Setterset_texture(value)
    Getterget_texture()

    The texture used for the line’s texture. Uses texture_mode for drawing style.


    • texture_mode
    Default
    Setterset_texture_mode(value)
    Getterget_texture_mode()

    The style to render the texture on the line. Use LineTextureMode constants.


    • width
    Default10.0
    Setterset_width(value)
    Getterget_width()

    Setterset_curve(value)
    Getterget_curve()

    The line’s width varies with the curve. The original width is simply multiply by the value of the Curve.

    • void add_point ( position, int at_position=-1 )

    Adds a point at the position. Appends the point at the end of the line.

    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.


    • void clear_points ( )

    Removes all points from the line.


    • get_point_count ( ) const

    Returns the Line2D’s amount of points.


    • Vector2 get_point_position ( i ) const

    Returns point i‘s position.


    Removes the point at index i from the line.


    • void set_point_position ( int i, position )

    Overwrites the position in point with the supplied position.