Skip to main content

World

Description:

  A world is an object that contains all bodies and joints.

type

Type: Function.

Description:

  Gets the type of the object as a string.

Signature:

type: function(self: World): 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: World, 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: World): boolean

Returns:

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

destroy

Type: Function.

Description:

  Destroys the world, taking all bodies, joints, fixtures and their shapes with it. An error will occur if you attempt to use any of the destroyed objects after calling this function.

Signature:

destroy: function(self: World)

isDestroyed

Type: Function.

Description:

  Gets whether the World is destroyed. Destroyed worlds cannot be used.

Signature:

isDestroyed: function(self: World): boolean

Returns:

Return TypeDescription
booleanWhether the World is destroyed.

update

Type: Function.

Description:

  Update the state of the world.

Signature:

update: function(self: World, delta_time: number, velocity_iterations?: integer, position_iterations?: integer)

Parameters:

ParameterTypeDescription
delta_timenumberThe time (in seconds) to advance the physics simulation.
velocity_iterationsintegerThe maximum number of steps used to determine the new velocities when resolving a collision. (Default: 8.)
position_iterationsintegerThe maximum number of steps used to determine the new positions when resolving a collision. (Default: 3.)

setGravity

Type: Function.

Description:

  Set the gravity of the world.

Signature:

setGravity: function(self: World, x: number, y: number)

Parameters:

ParameterTypeDescription
xnumberThe x component of gravity.
ynumberThe y component of gravity.

getGravity

Type: Function.

Description:

  Get the gravity of the world.

Signature:

getGravity: function(self: World): number, number

Returns:

Return TypeDescription
numberThe x component of gravity.
numberThe y component of gravity.

setSleepingAllowed

Type: Function.

Description:

  Sets the sleep behaviour of the world.

Signature:

setSleepingAllowed: function(self: World, allowed: boolean)

Parameters:

ParameterTypeDescription
allowedbooleanTrue if bodies in the world are allowed to sleep, or false if not.

isSleepingAllowed

Type: Function.

Description:

  Gets the sleep behaviour of the world.

Signature:

isSleepingAllowed: function(self: World): boolean

Returns:

Return TypeDescription
booleanTrue if bodies in the world are allowed to sleep, or false if not.

queryBoundingBox

Type: Function.

Description:

  Calls a function for each fixture inside the specified area by searching for any overlapping bounding box (Fixture:getBoundingBox).

Signature:

queryBoundingBox: function(self: World, x1: number, y1: number, x2: number, y2: number, callback: function(any): boolean)

Parameters:

ParameterTypeDescription
x1numberThe x position of the top-left point.
y1numberThe y position of the top-left point.
x2numberThe x position of the bottom-right point.
y2numberThe y position of the bottom-right point.
callbackfunctionThis function gets passed one argument, the fixture, and should return a boolean. The search will continue if it is true or stop if it is false.

rayCast

Type: Function.

Description:

  Casts a ray and calls a function for each fixtures it intersects. Overload details:

  1. There is a bug in LÖVE 0.8.0 where the normal vector passed to the callback function gets scaled by love.physics.getMeter.

Signature:

rayCast: function(self: World, x1: number, y1: number, x2: number, y2: number, callback: function(any, number, number, number, number, number): number)

Parameters:

ParameterTypeDescription
x1numberThe x position of the starting point of the ray.
y1numberThe x position of the starting point of the ray.
x2numberThe x position of the end point of the ray.
y2numberThe x value of the surface normal vector of the shape edge.
callbackfunctionA function called for each fixture intersected by the ray. The function gets six arguments and should return a number as a control value. The intersection points fed into the function will be in an arbitrary order. If you wish to find the closest point of intersection, you'll need to do that yourself within the function. The easiest way to do that is by using the fraction value.

setCallbacks

Type: Function.

Description:

  Sets functions for the collision callbacks during the world update. Four Lua functions can be given as arguments. The value nil removes a function. When called, each function will be passed three arguments. The first two arguments are the colliding fixtures and the third argument is the Contact between them. The postSolve callback additionally gets the normal and tangent impulse for each contact point. See notes. If you are interested to know when exactly each callback is called, consult a Box2d manual

Signature:

setCallbacks: function(self: World, begin_contact?: function(any, any, any), end_contact?: function(any, any, any), pre_solve?: function(any, any, any), post_solve?: function(any, any, any, ...: number))

Parameters:

ParameterTypeDescription
begin_contactfunctionGets called when two fixtures begin to overlap.
end_contactfunctionGets called when two fixtures cease to overlap. This will also be called outside of a world update, when colliding objects are destroyed.
pre_solvefunctionGets called before a collision gets resolved. (Default: nil.)
post_solvefunctionGets called after the collision has been resolved. (Default: nil.)

getCallbacks

Type: Function.

Description:

  Returns functions for the callbacks during the world update.

Signature:

getCallbacks: function(self: World): function(any, any, any) | nil, function(any, any, any) | nil, function(any, any, any) | nil, function(any, any, any, ...: number) | nil

Parameters:

ParameterTypeDescription
...numberThe ... parameter.

Returns:

Return TypeDescription
functionGets called when two fixtures begin to overlap.
functionGets called when two fixtures cease to overlap.
functionGets called before a collision gets resolved.
functionGets called after the collision has been resolved.