Up to date
This page is up to date for Godot 4.2
.
If you still find outdated information, please open an issue.
Polygon2D¶
继承: Node2D < CanvasItem < Node < Object
2D 多边形。
描述¶
Polygon2D 由一组点定义。每个点都连接到下一个点,最后一个点连接到第一个点,从而形成一个封闭的多边形。Polygon2D 可以填充颜色(纯色或渐变),也可以填充给定的纹理。
属性¶
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
方法¶
void |
add_bone ( NodePath path, PackedFloat32Array weights ) |
void |
clear_bones ( ) |
void |
erase_bone ( int index ) |
get_bone_count ( ) const |
|
get_bone_path ( int index ) const |
|
get_bone_weights ( int index ) const |
|
void |
set_bone_path ( int index, NodePath path ) |
void |
set_bone_weights ( int index, PackedFloat32Array weights ) |
属性说明¶
bool antialiased = false
如果为 true
,则多边形边缘将进行抗锯齿。
Array bones = []
分配的 skeleton 所使用的 Bone2D 节点的内部列表。使用 Polygon2D 编辑器编辑(顶部工具栏的“UV”按钮)。
Color color = Color(1, 1, 1, 1)
该多边形的填充颜色。如果设置了 texture,它将乘以该颜色。它也将是未在 vertex_colors 中设置的顶点的默认颜色。
int internal_vertex_count = 0
内部顶点的数量,用于 UV 映射。
float invert_border = 100.0
添加了当 invert_enabled 被设置为 true
时应用于边界框的填充。将该值设置得太小可能会产生一个“Bad Polygon”错误。
bool invert_enabled = false
如果为 true
,则多边形将被反转,包含定义点之外的区域并延伸到 invert_border。
Vector2 offset = Vector2(0, 0)
应用于每个顶点的位置偏移量。
PackedVector2Array polygon = PackedVector2Array()
void set_polygon ( PackedVector2Array value )
PackedVector2Array get_polygon ( )
多边形的顶点列表。最后一点将连接到第一个点。
注意:返回的是 PackedVector2Array 的副本,不是引用。
Array polygons = []
多边形数量大于一时的多边形列表。每个独立的多边形都作为 PackedInt32Array 存储,其中的每个 int 都是对 polygon 某个点的索引。如果为空,则会忽略这个属性,得到由 polygon 中所有点构成的单个多边形,顺序与存储顺序一致。
NodePath skeleton = NodePath("")
指向 Skeleton2D 节点的路径,用于对这个多边形进行基于骨架的变形。如果为空或无效,则不会使用骨架变形。
Texture2D texture
该多边形的填充纹理。使用 uv 设置纹理坐标。
Vector2 texture_offset = Vector2(0, 0)
多边形的 texture 纹理的偏移量。如果设置为 Vector2(0, 0)
,则纹理的原点(其左上角)将放置在该多边形的位置。
float texture_rotation = 0.0
纹理的旋转弧度。
Vector2 texture_scale = Vector2(1, 1)
使用 texture 时乘以 uv 坐标的量。值越大,纹理越小,反之亦然。
PackedVector2Array uv = PackedVector2Array()
void set_uv ( PackedVector2Array value )
PackedVector2Array get_uv ( )
多边形每个顶点的纹理坐标。每个多边形顶点应该有一个 UV 值。如果数量少,则未定义的顶点将使用 Vector2(0, 0)
。
PackedColorArray vertex_colors = PackedColorArray()
void set_vertex_colors ( PackedColorArray value )
PackedColorArray get_vertex_colors ( )
每个顶点的颜色。颜色在顶点之间插值,从而产生平滑的渐变。每个多边形顶点应该有一个。如果数量较少,则未定义的顶点将使用 color。
方法说明¶
void add_bone ( NodePath path, PackedFloat32Array weights )
添加指定 path
和 weights
的骨骼。
void clear_bones ( )
删除这个 Polygon2D 的所有骨骼。
void erase_bone ( int index )
从这个 Polygon2D 中删除指定的骨骼。
int get_bone_count ( ) const
返回这个 Polygon2D 中骨骼的数量。
NodePath get_bone_path ( int index ) const
返回与指定骨骼相关联的节点的路径。
PackedFloat32Array get_bone_weights ( int index ) const
返回指定骨骼的权重值。
void set_bone_path ( int index, NodePath path )
设置与指定骨骼相关联的节点的路径。
void set_bone_weights ( int index, PackedFloat32Array weights )
设置指定骨骼的权重值。