Polygon2D
A 2D polygon.
Polygon2D.swift:11class Polygon2D
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.
Superclasses
class Node2D
A 2D game object, inherited by all 2D-related nodes. Has a position, rotation, scale, and Z index.
Citizens in SwiftGodot
Conformances
protocol CustomStringConvertible
A type with a customized textual representation.
protocol Equatable
A type that can be compared for value equality.
protocol Hashable
A type that can be hashed into a
Hasher
to produce an integer hash value.protocol Identifiable<ID>
A class of types whose instances hold the value of an entity with stable identity.
protocol VariantRepresentable
Types that conform to VariantRepresentable can be stored directly in
Variant
with no conversion. These include all of the Variant types from Godot (for exampleGString
,Rect
,Plane
), Godot objects (those that subclass SwiftGodot.Object) as well as the built-in Swift types UInt8, Int64 and Double.protocol VariantStorable
Types that conform to VariantStorable can be stored in a Variant and can be extracted back out of a Variant.
Type members
Instance members
var antialiased: Bool
If
true
, polygon edges will be anti-aliased.var color: Color
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 invertexColors
.var internalVertexCount: Int32
Number of internal vertices, used for UV mapping.
var invertBorder: Double
Added padding applied to the bounding box when
invertEnabled
is set totrue
. Setting this value too small may result in a “Bad Polygon” error.var invertEnabled: Bool
If
true
, the polygon will be inverted, containing the area outside the defined points and extending to theinvertBorder
.var offset: Vector2
The offset applied to each vertex.
var polygon: PackedVector2Array
The polygon’s list of vertices. The final point will be connected to the first.
var polygons: GArray
The list of polygons, in case more than one is being represented. Every individual polygon is stored as a
PackedInt32Array
where each integer is an index to a point inpolygon
. If empty, this property will be ignored, and the resulting single polygon will be composed of all points inpolygon
, using the order they are stored in.var skeleton: NodePath
Path to a
Skeleton2D
node used for skeleton-based deformations of this polygon. If empty or invalid, skeletal deformations will not be used.var texture: Texture2D?
The polygon’s fill texture. Use
uv
to set texture coordinates.var textureOffset: Vector2
Amount to offset the polygon’s
texture
. If set toVector2(0, 0)
, the texture’s origin (its top-left corner) will be placed at the polygon’s position.var textureRotation: Double
The texture’s rotation in radians.
var textureScale: Vector2
Amount to multiply the
uv
coordinates when usingtexture
. Larger values make the texture smaller, and vice versa.var 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)
.var vertexColors: 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
.func addBone(path: NodePath, weights: PackedFloat32Array
) Adds a bone with the specified
path
andweights
.func clearBones(
) Removes all bones from this
Polygon2D
.func eraseBone(index: Int32
) Removes the specified bone from this
Polygon2D
.func getBoneCount(
) -> Int32 Returns the number of bones in this
Polygon2D
.func getBonePath(index: Int32
) -> NodePath Returns the path to the node associated with the specified bone.
func getBoneWeights(index: Int32
) -> PackedFloat32Array Returns the weight values of the specified bone.
func setBonePath(index: Int32, path: NodePath
) Sets the path to the node associated with the specified bone.
func setBoneWeights(index: Int32, weights: PackedFloat32Array
) Sets the weight values for the specified bone.