Attention: Here be dragons

This is the latest (unstable) version of this documentation, which may document features not available in or compatible with released stable versions of Godot.

Line2D

Inherits: Node2D < CanvasItem < Node < Object

A 2D polyline that can optionally be textured.

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.

Tutorials

Properties

bool

antialiased

false

LineCapMode

begin_cap_mode

0

bool

closed

false

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:

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 sharp_limit), the joint falls back to LINE_JOINT_BEVEL to prevent very long miters.

LineJointMode LINE_JOINT_BEVEL = 1

Makes the polyline's joints bevelled/chamfered, connecting the sides of the two segments with a simple line.

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


enum LineCapMode:

LineCapMode LINE_CAP_NONE = 0

Draws no line cap.

LineCapMode LINE_CAP_BOX = 1

Draws the line cap as a box, slightly extending the first/last segment.

LineCapMode LINE_CAP_ROUND = 2

Draws the line cap as a semicircle attached to the first/last segment.


enum LineTextureMode:

LineTextureMode LINE_TEXTURE_NONE = 0

Takes the left pixels of the texture and renders them over the whole polyline.

LineTextureMode LINE_TEXTURE_TILE = 1

Tiles the texture over the polyline. CanvasItem.texture_repeat of the Line2D node must be CanvasItem.TEXTURE_REPEAT_ENABLED or CanvasItem.TEXTURE_REPEAT_MIRROR for it to work properly.