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

繼承: Node2D < CanvasItem < Node < Object

可以選擇紋理的 2D 折線。

說明

該節點繪製一條 2D 折線,即由線段連接的多個點組成的形狀。Line2D 不是數學折線,即線段不是無限細的。它的目的是算繪,它可以著色,也可以選擇紋理。

警告:某些配置可能無法很好地繪製,例如非常銳利的角度。在這些情況下,節點使用後備繪製邏輯來看起來不錯。

注意: Line2D 使用 2D 網格繪製。

教學

屬性

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

方法

void

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

void

clear_points()

int

get_point_count() const

Vector2

get_point_position(index: int) const

void

remove_point(index: int)

void

set_point_position(index: int, position: Vector2)


列舉

enum LineJointMode: 🔗

LineJointMode LINE_JOINT_SHARP = 0

使折線的關節成為尖頭,透過延伸兩個線段的側面直到它們相交來連接它們。如果關節的旋轉太大(基於sharp_limit),則關節回落到LINE_JOINT_BEVEL 以防止過長的斜接。

LineJointMode LINE_JOINT_BEVEL = 1

使多段線的接頭傾斜/倒角,用一條簡單的線連接兩個線段的側面。

LineJointMode LINE_JOINT_ROUND = 2

使折線的關節變圓,用圓弧連接兩個線段的側面。此圓弧的細部取決於round_precision


enum LineCapMode: 🔗

LineCapMode LINE_CAP_NONE = 0

不繪製線條的端點。

LineCapMode LINE_CAP_BOX = 1

將線帽繪製為盒子,稍微延伸第一個/最後一個線段。

LineCapMode LINE_CAP_ROUND = 2

將線條端點繪製為圓形。


enum LineTextureMode: 🔗

LineTextureMode LINE_TEXTURE_NONE = 0

獲取紋理的左側圖元並在整個線條上算繪它。

LineTextureMode LINE_TEXTURE_TILE = 1

將紋理平鋪在該線條上。該 Line2D 節點的 CanvasItem.texture_repeat 必須為 CanvasItem.TEXTURE_REPEAT_ENABLEDCanvasItem.TEXTURE_REPEAT_MIRROR,才能正常工作。

LineTextureMode LINE_TEXTURE_STRETCH = 2

沿該線條拉伸紋理。該 Line2D 節點的 CanvasItem.texture_repeat 必須為 CanvasItem.TEXTURE_REPEAT_DISABLED,以獲得最佳效果。


屬性說明

bool antialiased = false 🔗

  • void set_antialiased(value: bool)

  • bool get_antialiased()

如果為 true,則線條的邊界將使用抗鋸齒。

注意:Line2D 在使用抗鋸齒時,不會通過批次處理來加速。


LineCapMode begin_cap_mode = 0 🔗

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


bool closed = false 🔗

  • void set_closed(value: bool)

  • bool is_closed()

如果 true 且折線有超過 2 個點,則最後一個點和第一個點將透過線段連接。

注意:如果提供了width_curve,則不保證閉合線段的形狀是無縫的。

注意:首先繪製結束線段和第一線段之間的連接點,並在開始時對gradientwidth_curve進行取樣。這是未來版本中可能會變更的實作細節。


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

  • void set_default_color(value: Color)

  • Color get_default_color()

線條的顏色。如果設定了漸變,則不會生效。


LineCapMode end_cap_mode = 0 🔗

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


Gradient gradient 🔗

從頭到尾貫穿整條線的漸變色。如果設定了漸變,則不會使用預設顏色。


LineJointMode joint_mode = 0 🔗

The style of the connections between segments of the polyline.


PackedVector2Array points = PackedVector2Array() 🔗

折線的點,以局部 2D 座標解釋。線段在此陣列中的相鄰點之間繪製。

Note: The returned array is copied and any changes to it will not update the original property value. See PackedVector2Array for more details.


int round_precision = 8 🔗

  • void set_round_precision(value: int)

  • int get_round_precision()

用於圓角接頭和帽的平滑度。值越高,邊角越平滑,但算繪和更新的要求更高。


float sharp_limit = 2.0 🔗

  • void set_sharp_limit(value: float)

  • float get_sharp_limit()

決定折線的斜接限制。通常,當 joint_mode 設定為 LINE_JOINT_SHARP 時,銳角會退回到使用 LINE_JOINT_BEVEL 關節的邏輯來防止非常長長的斜接。此屬性的值較高意味著會以更尖銳的角度退回到斜角接頭。


Texture2D texture 🔗

The texture used for the polyline. Uses texture_mode for drawing style.


LineTextureMode texture_mode = 0 🔗

The style to render the texture of the polyline.


float width = 10.0 🔗

多邊形的寬度。


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.


方法說明

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

在指定的位置 position 新增一個點,該位置相對於該線段自身的位置。新的點會被加入到點的列表末尾。

如果給出 index,則將新點插入到由索引 index 標識的已有點之前。從 index 開始的每個已有點都會進一步向下移動點列表。索引必須大於或等於 0,並且不得超過線段中已有點的數量。請參閱 get_point_count()


void clear_points() 🔗

移除直線上的所有點。


int get_point_count() const 🔗

返回該直線中的點的數量。


Vector2 get_point_position(index: int) const 🔗

返回索引為 index 的點的位置。


void remove_point(index: int) 🔗

移除該直線中索引為 index 的點。


void set_point_position(index: int, position: Vector2) 🔗

用提供的 position 覆蓋索引 index 處的點的位置。