geom

GeomPolygon2DGeom.Nodes.Polygon2D

Inherits: Node2D

C#: make one with the Geom.Nodes.Polygon2D() factory, then set and read its properties by name with Set and Get, or in the Inspector, where the node is GeomPolygon2D.

A filled polygon with any number of points, on the canvas.

For an outline, draw the points as a closed GeomPolyline2D.

From code

The code used to generate this page's thumbnail.

# Concave is fine.
var poly := GeomPolygon2D.new()
poly.position = c
poly.points = PackedVector2Array([
	Vector2(0, -r), Vector2(r * 0.34, -r * 0.3),
	Vector2(r, -r * 0.2), Vector2(r * 0.45, r * 0.35),
	Vector2(r * 0.6, r), Vector2(0, r * 0.52),
	Vector2(-r * 0.6, r), Vector2(-r * 0.45, r * 0.35),
	Vector2(-r, -r * 0.2), Vector2(-r * 0.34, -r * 0.3)])
poly.color = AMBER
add_child(poly)
// Concave is fine.
var poly = Geom.Nodes.Polygon2D();
poly.Position = c;
poly.Set("points", new Vector2[] {
	new Vector2(0, -r), new Vector2(r * 0.34f, -r * 0.3f),
	new Vector2(r, -r * 0.2f), new Vector2(r * 0.45f, r * 0.35f),
	new Vector2(r * 0.6f, r), new Vector2(0, r * 0.52f),
	new Vector2(-r * 0.6f, r), new Vector2(-r * 0.45f, r * 0.35f),
	new Vector2(-r, -r * 0.2f), new Vector2(-r * 0.34f, -r * 0.3f)});
poly.Set("color", AMBER);
AddChild(poly);

Properties

BlendMode blend_mode Geom.BLEND_TRANSPARENTGeom.BlendMode.Transparent
Color color Color(1, 1, 1, 1)
bool convex_only false
Resource fill null
PackedVector2Array points PackedVector2Array(0, -90, -90, -18, -45, 90, 45, 90, 90, -18)

Enumerations

enum Geom.BlendMode

Geom.BLEND_OPAQUEGeom.BlendMode.Opaque = 0
Sorts by position. Hard edges: no anti-aliasing, and alpha is ignored.
Geom.BLEND_TRANSPARENTGeom.BlendMode.Transparent = 1
Standard alpha blending. The default.
Geom.BLEND_ADDITIVEGeom.BlendMode.Additive = 2
Adds this color to what is behind.
Geom.BLEND_MULTIPLYGeom.BlendMode.Multiply = 3
Multiplies what is behind by this color.
Geom.BLEND_SUBTRACTGeom.BlendMode.Subtract = 4
Subtracts this color from the background.
Geom.BLEND_TRANSPARENT_DEPTHGeom.BlendMode.TransparentDepth = 5
Transparent, but writes depth, so shapes with alpha 1 sort by position with anti-aliased edges. A translucent color behaves like Transparent.

Property descriptions

BlendMode blend_mode = Geom.BLEND_TRANSPARENTGeom.BlendMode.Transparent

How the shape blends with what is behind it. Transparent Depth acts like Transparent on the canvas.

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

Fill color.

bool convex_only = false

Skip the work a concave shape needs. Cheaper, but a concave polygon then draws wrong.

Resource fill = null

A gradient in place of color. Takes GeomFillLinear.

PackedVector2Array points = PackedVector2Array(0, -90, -90, -18, -45, 90, 45, 90, 90, -18)

The corners, in order. Fewer than three draws nothing.