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.

Polygon2D

繼承: Node2D < CanvasItem < Node < Object

2D 多邊形。

說明

Polygon2D 由一組點定義。每個點都連接到下一個點,最後一個點連接到第一個點,從而形成一個封閉的多邊形。Polygon2D 可以填充顏色(純色或漸變),也可以填充給定的紋理。

屬性

bool

antialiased

false

Color

color

Color(1, 1, 1, 1)

int

internal_vertex_count

0

float

invert_border

100.0

bool

invert_enabled

false

Vector2

offset

Vector2(0, 0)

PackedVector2Array

polygon

PackedVector2Array()

Array

polygons

[]

NodePath

skeleton

NodePath("")

Texture2D

texture

Vector2

texture_offset

Vector2(0, 0)

float

texture_rotation

0.0

Vector2

texture_scale

Vector2(1, 1)

PackedVector2Array

uv

PackedVector2Array()

PackedColorArray

vertex_colors

PackedColorArray()

方法

void

add_bone(path: NodePath, weights: PackedFloat32Array)

void

clear_bones()

void

erase_bone(index: int)

int

get_bone_count() const

NodePath

get_bone_path(index: int) const

PackedFloat32Array

get_bone_weights(index: int) const

void

set_bone_path(index: int, path: NodePath)

void

set_bone_weights(index: int, weights: PackedFloat32Array)


屬性說明

bool antialiased = false 🔗

  • void set_antialiased(value: bool)

  • bool get_antialiased()

如果為 true,則多邊形邊緣將進行抗鋸齒。


Color color = Color(1, 1, 1, 1) 🔗

The polygon's fill color. If texture is set, it will be multiplied by this color. It will also be the default color for vertices not set in vertex_colors.


int internal_vertex_count = 0 🔗

  • void set_internal_vertex_count(value: int)

  • int get_internal_vertex_count()

內部頂點的數量,用於 UV 對應。


float invert_border = 100.0 🔗

  • void set_invert_border(value: float)

  • float get_invert_border()

新增了當 invert_enabled 被設定為 true 時套用於邊界框的填充。將該值設定得太小可能會產生一個“Bad Polygon”錯誤。


bool invert_enabled = false 🔗

  • void set_invert_enabled(value: bool)

  • bool get_invert_enabled()

如果為 true,則多邊形將被反轉,包含定義點之外的區域並延伸到 invert_border


Vector2 offset = Vector2(0, 0) 🔗

套用於每個頂點的位置偏移量。


PackedVector2Array polygon = PackedVector2Array() 🔗

The polygon's list of vertices. The final point will be connected to the first.

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


Array polygons = [] 🔗

  • void set_polygons(value: Array)

  • Array get_polygons()

多邊形數量大於一時的多邊形列表。每個獨立的多邊形都作為 PackedInt32Array 存儲,其中的每個 int 都是對 polygon 某個點的索引。如果為空,則會忽略這個屬性,得到由 polygon 中所有點構成的單個多邊形,順序與儲存順序一致。


NodePath skeleton = NodePath("") 🔗

指向 Skeleton2D 節點的路徑,用於對這個多邊形進行基於骨架的變形。如果為空或無效,則不會使用骨架變形。


Texture2D texture 🔗

The polygon's fill texture. Use uv to set texture coordinates.


Vector2 texture_offset = Vector2(0, 0) 🔗

  • void set_texture_offset(value: Vector2)

  • Vector2 get_texture_offset()

Amount to offset the polygon's texture. If set to Vector2(0, 0), the texture's origin (its top-left corner) will be placed at the polygon's position.


float texture_rotation = 0.0 🔗

  • void set_texture_rotation(value: float)

  • float get_texture_rotation()

紋理的旋轉弧度。


Vector2 texture_scale = Vector2(1, 1) 🔗

Amount to multiply the uv coordinates when using texture. Larger values make the texture smaller, and vice versa.


PackedVector2Array uv = PackedVector2Array() 🔗

Texture coordinates for each vertex of the polygon. There should be one UV value per polygon vertex. If there are fewer, undefined vertices will use Vector2(0, 0).

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


PackedColorArray vertex_colors = PackedColorArray() 🔗

Color for each vertex. Colors are interpolated between vertices, resulting in smooth gradients. There should be one per polygon vertex. If there are fewer, undefined vertices will use color.

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


方法說明

void add_bone(path: NodePath, weights: PackedFloat32Array) 🔗

新增指定 pathweights 的骨骼。


void clear_bones() 🔗

刪除這個 Polygon2D 的所有骨骼。


void erase_bone(index: int) 🔗

從這個 Polygon2D 中刪除指定的骨骼。


int get_bone_count() const 🔗

返回這個 Polygon2D 中骨骼的數量。


NodePath get_bone_path(index: int) const 🔗

返回與指定骨骼相關聯的節點的路徑。


PackedFloat32Array get_bone_weights(index: int) const 🔗

返回指定骨骼的權重值。


void set_bone_path(index: int, path: NodePath) 🔗

設定與指定骨骼相關聯的節點的路徑。


void set_bone_weights(index: int, weights: PackedFloat32Array) 🔗

設定指定骨骼的權重值。