Line2D

Inherits: Node2D < CanvasItem < Node < Object

A 2D line.

Description

A line through several points in 2D space.

Tutorials

Properties

bool

antialiased

false

LineCapMode

begin_cap_mode

0

Color

default_color

Color(1, 1, 1, 1)

LineCapMode

end_cap_mode

0

Gradient

gradient

LineJointMode

joint_mode

0

PackedVector2Array

points

PackedVector2Array()

int

round_precision

8

float

sharp_limit

2.0

Texture2D

texture

LineTextureMode

texture_mode

0

float

width

10.0

Curve

width_curve

Methods

void

add_point ( Vector2 position, int index=-1 )

void

clear_points ( )

int

get_point_count ( ) const

Vector2

get_point_position ( int index ) const

void

remove_point ( int index )

void

set_point_position ( int index, Vector2 position )

Enumerations

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

Property Descriptions

Default

false

Setter

set_antialiased(value)

Getter

get_antialiased()

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

Note: Line2D is not accelerated by batching when being anti-aliased.


Default

0

Setter

set_begin_cap_mode(value)

Getter

get_begin_cap_mode()

Controls the style of the line's first point. Use LineCapMode constants.


Default

Color(1, 1, 1, 1)

Setter

set_default_color(value)

Getter

get_default_color()

The line's color. Will not be used if a gradient is set.


Default

0

Setter

set_end_cap_mode(value)

Getter

get_end_cap_mode()

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


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.


Default

0

Setter

set_joint_mode(value)

Getter

get_joint_mode()

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


Default

PackedVector2Array()

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.


  • 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 width. For thin lines, this value should be reduced to a number between 2 and 4 to improve performance.


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 joint_mode is set to LINE_JOINT_SHARP.


Setter

set_texture(value)

Getter

get_texture()

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


Default

0

Setter

set_texture_mode(value)

Getter

get_texture_mode()

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


Default

10.0

Setter

set_width(value)

Getter

get_width()

The line's width.


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

  • void add_point ( Vector2 position, 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 get_point_count.


  • void clear_points ( )

Removes all points from the line.


  • int get_point_count ( ) const

Returns the number of points in the line.


Returns the position of the point at index index.


  • void remove_point ( int index )

Removes the point at index index from the line.


  • void set_point_position ( int index, Vector2 position )

Overwrites the position of the point at index index with the supplied position.