Skip to content

Polygon2D

Inherits: Entity2D < CanvasItem < Entity < Object

A 2D polygon.

A Polygon2D is defined by a set of points. Each point is connected to the next, with the final point being connected to the first, resulting in a closed polygon. Polygon2Ds can be filled with color (solid or gradient) or filled with a given texture.

Type Name Default
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 []
EntityPath skeleton EntityPath("")
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()
Returns Method
void add_bone(path: EntityPath, weights: PackedFloat32Array)
void clear_bones()
void erase_bone(index: int)
int get_bone_count() const
EntityPath get_bone_path(index: int) const
PackedFloat32Array get_bone_weights(index: int) const
void set_bone_path(index: int, path: EntityPath)
void set_bone_weights(index: int, weights: PackedFloat32Array)

antialiased

bool antialiased = false

If true, polygon edges will be anti-aliased.

color

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.

internal_vertex_count

int internal_vertex_count = 0

Number of internal vertices, used for UV mapping.

invert_border

float invert_border = 100.0

Added padding applied to the bounding box when invert_enabled is set to true. Setting this value too small may result in a “Bad Polygon” error.

invert_enabled

bool invert_enabled = false

If true, the polygon will be inverted, containing the area outside the defined points and extending to the invert_border.

offset

Vector2 offset = Vector2(0, 0)

The offset applied to each vertex.

polygon

PackedVector2Array polygon = PackedVector2Array()

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

polygons

Array polygons = []

The list of polygons, in case more than one is being represented. Every individual polygon is stored as a PackedInt32Array where each int is an index to a point in polygon. If empty, this property will be ignored, and the resulting single polygon will be composed of all points in polygon, using the order they are stored in.

skeleton

EntityPath skeleton = EntityPath("")

Path to a Skeleton2D node used for skeleton-based deformations of this polygon. If empty or invalid, skeletal deformations will not be used.

texture

Texture2D texture

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

texture_offset

Vector2 texture_offset = Vector2(0, 0)

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.

texture_rotation

float texture_rotation = 0.0

The texture’s rotation in radians.

texture_scale

Vector2 texture_scale = Vector2(1, 1)

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

uv

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).

vertex_colors

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.

add_bone

void add_bone(path: EntityPath, weights: PackedFloat32Array)

Adds a bone with the specified path and weights.

clear_bones

void clear_bones()

Removes all bones from this Polygon2D.

erase_bone

void erase_bone(index: int)

Removes the specified bone from this Polygon2D.

get_bone_count

int get_bone_count() const

Returns the number of bones in this Polygon2D.

get_bone_path

EntityPath get_bone_path(index: int) const

Returns the path to the node associated with the specified bone.

get_bone_weights

PackedFloat32Array get_bone_weights(index: int) const

Returns the weight values of the specified bone.

set_bone_path

void set_bone_path(index: int, path: EntityPath)

Sets the path to the node associated with the specified bone.

set_bone_weights

void set_bone_weights(index: int, weights: PackedFloat32Array)

Sets the weight values for the specified bone.