Shape2D
Abstract base class for 2D shapes used for physics collision.
Shape2D.swift:20class Shape2D
Abstract base class for all 2D shapes, intended for use in physics.
Performance: Primitive shapes, especially CircleShape2D
, are fast to check collisions against. ConvexPolygonShape2D
is slower, and ConcavePolygonShape2D
is the slowest.
Superclasses
class Resource
Base class for serializable objects.
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 customSolverBias: Double
The shape’s custom solver bias. Defines how much bodies react to enforce contact separation when this shape is involved.
func collide(localXform: Transform2D, withShape: Shape2D?, shapeXform: Transform2D
) -> Bool Returns
true
if this shape is colliding with another.func collideAndGetContacts(localXform: Transform2D, withShape: Shape2D?, shapeXform: Transform2D
) -> PackedVector2Array Returns a list of contact point pairs where this shape touches another.
func collideWithMotion(localXform: Transform2D, localMotion: Vector2, withShape: Shape2D?, shapeXform: Transform2D, shapeMotion: Vector2
) -> Bool Returns whether this shape would collide with another, if a given movement was applied.
func collideWithMotionAndGetContacts(localXform: Transform2D, localMotion: Vector2, withShape: Shape2D?, shapeXform: Transform2D, shapeMotion: Vector2
) -> PackedVector2Array Returns a list of contact point pairs where this shape would touch another, if a given movement was applied.
func draw(canvasItem: RID, color: Color
) Draws a solid shape onto a
CanvasItem
with theRenderingServer
API filled with the specifiedcolor
. The exact drawing method is specific for each shape and cannot be configured.func getRect(
) -> Rect2 Returns a
Rect2
representing the shapes boundary.
Subclasses
class CapsuleShape2D
A 2D capsule shape used for physics collision.
class CircleShape2D
A 2D circle shape used for physics collision.
class ConcavePolygonShape2D
A 2D polyline shape used for physics collision.
class ConvexPolygonShape2D
A 2D convex polygon shape used for physics collision.
class RectangleShape2D
A 2D rectangle shape used for physics collision.
class SegmentShape2D
A 2D line segment shape used for physics collision.
class SeparationRayShape2D
A 2D ray shape used for physics collision that tries to separate itself from any collider.
class WorldBoundaryShape2D
A 2D world boundary (half-plane) shape used for physics collision.