Skip to main content

Shape

Description:

  Shapes are solid 2d geometrical objects which handle the mass and collision of a Body in love.physics.

type​

Type: Function.

Description:

  Gets the type of the object as a string.

Signature:

type: function(self: Shape): string

Returns:

Return TypeDescription
stringThe type as a string.

Of​

Type: Function.

Description:

  Checks whether an object is of a certain type. If the object has the type with the specified name in its hierarchy, this function will return true.

Signature:

typeOf: function(self: Shape, type_name: string): boolean

Parameters:

ParameterTypeDescription
type_namestringThe name of the type to check for.

Returns:

Return TypeDescription
booleanTrue if the object is of the specified type, false otherwise.

release​

Type: Function.

Description:

  Destroys the object's Lua reference. The object will be completely deleted if it's not referenced by any other LÖVE object or thread. This method can be used to immediately clean up resources without waiting for Lua's garbage collector.

Signature:

release: function(self: Shape): boolean

Returns:

Return TypeDescription
booleanTrue if the object was released by this call, false if it had been previously released.

getType​

Type: Function.

Description:

  Gets a string representing the Shape. This function can be useful for conditional debug drawing.

Signature:

getType: function(self: Shape): string

Returns:

Return TypeDescription
stringThe type of the Shape.

getRadius​

Type: Function.

Description:

  Gets the radius of the shape's rounded skin.

Signature:

getRadius: function(self: Shape): number

Returns:

Return TypeDescription
numberThe radius in pixels.

setRadius​

Type: Function.

Description:

  Sets the radius of a CircleShape.

Signature:

setRadius: function(self: Shape, radius: number)

getChildCount​

Type: Function.

Description:

  Returns the number of child shapes.

Signature:

getChildCount: function(self: Shape): integer

testPoint​

Type: Function.

Description:

  Tests whether a point lies inside the transformed shape.

Signature:

testPoint: function(self: Shape, x: number, y: number, angle: number, point_x: number, point_y: number): boolean

rayCast​

Type: Function.

Description:

  Casts a ray against the transformed shape. Returns nil values on a miss.

Signature:

rayCast: function(self: Shape, x1: number, y1: number, x2: number, y2: number, maximum_fraction: number, x: number, y: number, angle: number, child_index?: integer): number | nil, number | nil, number | nil

computeAABB​

Type: Function.

Description:

  Computes the transformed axis-aligned bounding box.

Signature:

computeAABB: function(self: Shape, x: number, y: number, angle: number, child_index?: integer): number, number, number, number

computeMass​

Type: Function.

Description:

  Computes center, mass, and rotational inertia for a density.

Signature:

computeMass: function(self: Shape, density: number): number, number, number, number