Line2D
Inherits: Node2D < CanvasItem < Node < Object A 2D line.
Description
A line through several points in 2D space. Supports varying width and color over the line’s length, texturing, and several cap/joint types. 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 ProjectSettings.rendering/limits/buffers/canvas_polygon_buffer_size_kb and ProjectSettings.rendering/limits/buffers/canvas_polygon_index_buffer_size_kb.
Tutorials
- Matrix Transform Demo
- 2.5D Demo
Properties
Methods
Enumerations
LineJointMode: - LINE_JOINT_SHARP = 0 —- The line’s joints will be pointy. If
sharp_limitis 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.
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.
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
- bool antialiased
true, the line’s border will attempt to perform antialiasing by drawing thin OpenGL smooth lines on the line’s edges. Note: Line2D is not accelerated by batching if antialiased istrue. Note: Due to how it works, built-in antialiasing will not look correct for translucent lines and may not work on certain platforms. As a workaround, install the Antialiased Line2D add-on then create an AntialiasedLine2D node. That node relies on a texture with custom mipmaps to perform antialiasing. 2D batching is also still supported with those antialiased lines.
- LineCapMode begin_cap_mode LineCapMode constants.
- Color default_color The line’s color. Will not be used if a gradient is set.
- LineCapMode end_cap_mode LineCapMode constants.
- Gradient 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.
- LineJointMode joint_mode The style for the points between the start and the end.
- PoolVector2Array 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
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
2and4to improve performance.
- float sharp_limit joint_mode is set to LINE_JOINT_SHARP.
- Texture texture
texture_modefor drawing style.
- LineTextureMode texture_mode
textureon the line. Use LineTextureMode constants.
- float width The line’s width.
- Curve width_curve
The line’s width varies with the curve. The original width is simply multiply by the value of the Curve.
Method Descriptions
- add_point ( Vector2 position, int at_position=-1 )
position. Appends the point at the end of the line.at_positionis given, the point is inserted before the point numberat_position, moving that point (and every point after) after the inserted point. Ifat_positionis not given, or is an illegal value (at_position < 0orat_position >= [method get_point_count]), the point will be appended at the end of the point list.
- clear_points ( ) Removes all points from the line.
- int get_point_count ( ) const Returns the Line2D’s amount of points.
- Vector2 get_point_position ( int i ) const
i‘s position.
- remove_point ( int i )
ifrom the line.
- set_point_position ( int i, Vector2 position )
iwith the suppliedposition.
