Class reference

Line2D

Inherits Node2D

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.

Properties

bool antialiased = false

If true, the polyline's border will be anti-aliased. Note: Line2D is not accelerated by batching when being anti-aliased.

int begin_cap_mode = 0

The style of the beginning of the polyline, if closed is false.

bool closed = false

If true and the polyline has more than 2 points, the last point and the first one will be connected by a segment. Note: The shape of the closing segment is not guaranteed to be seamless if a width_curve is provided. Note: The joint between the closing segment and the first segment is drawn first and it samples the gradient and the width_curve at the beginning. This is an implementation detail that might change in a future version.

Color default_color = Color(1, 1, 1, 1)

The color of the polyline. Will not be used if a gradient is set.

int end_cap_mode = 0

The style of the end of the polyline, if closed is false.

Gradient gradient

The gradient is drawn through the whole line from start to finish. The default_color will not be used if this property is set.

int joint_mode = 0

The style of the connections between segments of the polyline.

PackedVector2Array points = PackedVector2Array()

The points of the polyline, interpreted in local 2D coordinates. Segments are drawn between the adjacent points in this array.

int round_precision = 8

The smoothness used for rounded joints and caps. Higher values result in smoother corners, but are more demanding to render and update.

float sharp_limit = 2.0

Determines the miter limit of the polyline. Normally, when joint_mode is set to LINE_JOINT_SHARP, sharp angles fall back to using the logic of LINE_JOINT_BEVEL joints to prevent very long miters. Higher values of this property mean that the fallback to a bevel joint will happen at sharper angles.

int texture_mode = 0

The style to render the texture of the polyline.

float width = 10.0

The polyline's width.

Curve width_curve

The polyline's width curve. The width of the polyline over its length will be equivalent to the value of the width curve over its domain. The width curve should be a unit Curve.

Methods

void add_point(Vector2 position, int index = -1)

Adds a point with the specified position relative to the polyline's own position. If no index is provided, the new point will be added to the end of the points array. If index is given, the new point is inserted before the existing point identified by index index. The indices of the points after the new point get increased by 1. The provided index must not exceed the number of existing points in the polyline. See get_point_count().

void clear_points()

Removes all points from the polyline, making it empty.

int get_point_count() const

Returns the number of points in the polyline.

Vector2 get_point_position(int index) const

Returns the position of the point at index index.

void remove_point(int index)

Removes the point at index index from the polyline.

void set_point_position(int index, Vector2 position)

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

Constants

LINE_JOINT_SHARP = 0

Enum: LineJointMode

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.

LINE_JOINT_BEVEL = 1

Enum: LineJointMode

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

LINE_JOINT_ROUND = 2

Enum: LineJointMode

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.

LINE_CAP_NONE = 0

Enum: LineCapMode

Draws no line cap.

LINE_CAP_BOX = 1

Enum: LineCapMode

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

LINE_CAP_ROUND = 2

Enum: LineCapMode

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

LINE_TEXTURE_NONE = 0

Enum: LineTextureMode

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

Tutorials

Source revision 5592dc3a7a61
Connection interrupted. Reload×

Rejoining the server...

Rejoin failed... trying again in seconds.

Failed to rejoin.
Please retry or reload the page.

The session has been paused by the server.

Failed to resume the session.
Please retry or reload the page.