b2d

Namespace: b2d Language: Lua Type: Defold Lua File: script_box2d.cpp Source: engine/gamesys/src/gamesys/scripts/box2d/script_box2d.cpp

Functions for interacting with Box2D.

API

b2Body

Type: TYPEDEF An opaque handle to the native Box2D body of a collision-object component. Obtain it with b2d.get_body and pass it to functions in b2d.body. The collision object owns the body, so the handle becomes invalid when its component or game object is deleted.

Parameters

Examples

local body = b2d.get_body("#collisionobject")
if body then
    print(b2d.body.get_position(body))
end

b2d.aabb

Type: STRUCT Box2D axis-aligned bounding box

Members

b2d.chain_definition

Type: STRUCT Box2D 3.x chain definition

Members

b2d.chain_geometry

Type: STRUCT Box2D chain geometry

Members

b2d.contact_data

Type: STRUCT Box2D contact data

Members

b2d.contact_point

Type: STRUCT Box2D contact manifold point

Members

b2d.explosion_definition

Type: STRUCT Box2D explosion definition

Members

b2d.filter

Type: STRUCT Box2D collision filter

Members

b2d.filter_options

Type: STRUCT Partial Box2D collision filter

Members

b2d.fixture_cast_hit

Type: STRUCT Box2D 2.x cast hit

Members

b2d.fixture_definition

Type: STRUCT Box2D 2.x fixture definition

Members

b2d.fixture_info

Type: STRUCT Box2D 2.x fixture information

Members

b2d.get_body

Type: FUNCTION Get the Box2D body from a collision object

Parameters

Returns

b2d.get_version

Type: FUNCTION Get the Box2D version information for the active backend.

Returns

b2d.get_world

Type: FUNCTION Get the Box2D world from the current collection

Returns

b2d.joint.distance_definition

Type: STRUCT Box2D distance-joint definition

Members

b2d.joint.filter_definition

Type: TYPEDEF The optional definition passed to b2d.joint.create_filter. Filter joints currently have no configurable fields, so omit the argument or pass an empty table. The type is reserved for future options.

Parameters

Examples

local body_a = b2d.get_body("#collisionobject_a")
local body_b = b2d.get_body("#collisionobject_b")
local joint = b2d.joint.create_filter(body_a, body_b, {})

b2d.joint.friction_definition

Type: STRUCT Box2D friction-joint definition

Members

b2d.joint.gear_definition

Type: STRUCT Box2D gear-joint definition

Members

b2d.joint.motor_definition

Type: STRUCT Box2D motor-joint definition

Members

b2d.joint.mouse_definition

Type: STRUCT Box2D mouse-joint definition

Members

b2d.joint.prismatic_definition

Type: STRUCT Box2D prismatic-joint definition

Members

b2d.joint.pulley_definition

Type: STRUCT Box2D pulley-joint definition

Members

b2d.joint.revolute_definition

Type: STRUCT Box2D revolute-joint definition

Members

b2d.joint.rope_definition

Type: STRUCT Box2D rope-joint definition

Members

b2d.joint.weld_definition

Type: STRUCT Box2D weld-joint definition

Members

b2d.joint.wheel_definition

Type: STRUCT Box2D wheel-joint definition

Members

b2d.mass_data

Type: STRUCT Mass properties for a Box2D body or shape.

Members

b2d.mover_capsule

Type: STRUCT Box2D mover capsule

Members

b2d.mover_plane

Type: STRUCT Box2D mover collision plane

Members

b2d.query_filter

Type: STRUCT Box2D world-query filter

Members

b2d.shape_cast_hit

Type: STRUCT Box2D 3.x cast hit

Members

b2d.shape_cast_output

Type: STRUCT Direct Box2D shape cast result

Members

b2d.shape_create_definition

Type: TYPEDEF Geometry and material properties accepted by b2d.body.create_shape. The geometry can be supplied in the shape field as a b2d.shape.definition, or its fields can be placed directly in this table. Material properties such as density, friction, restitution, and filter are optional.

Parameters

Examples

Create a circular shape using an inline geometry definition:

local body = b2d.get_body("#collisionobject")
local shape = b2d.body.create_shape(body, {
    type = b2d.shape.SHAPE_TYPE_CIRCLE,
    radius = 16,
    density = 1,
    friction = 0.4,
})

b2d.shape_info

Type: STRUCT Box2D 3.x shape information

Members

b2d.transform

Type: STRUCT World transform for a Box2D body.

Members

b2d.tree_stats

Type: STRUCT Box2D broad-phase query statistics

Members

b2d.version_info

Type: STRUCT Box2D version information

Members

b2d.world_counters

Type: STRUCT Box2D world counters

Members

b2d.world_profile

Type: STRUCT Box2D world profiling data

Members

b2World

Type: TYPEDEF An opaque handle to the Box2D physics world owned by the current collection. Obtain it with b2d.get_world and pass it to functions in b2d.world. The engine creates and destroys the world together with the collection; it cannot be constructed directly from Lua.

Parameters

Examples

local world = b2d.get_world()
if world then
    pprint(world)
end