B2.World:createBody

From GiderosMobile

This page contains changes which are not marked for translation.


Available since: Gideros 2011.6
Class: b2.World

Description

Creates a rigid body given a definition. The body definition is given as an ordinary table. The fields of the body definition table are:

type: (number) The body type: b2.STATIC_BODY, b2.KINEMATIC_BODY, or b2.DYNAMIC_BODY. Note: if a dynamic body would have zero mass, the mass is set to one.
position: (table) The world position of the body (see the example below to understand how this table is set). Avoid creating bodies at the origin since this can lead to many overlapping shapes.
angle: (number) The world angle of the body in radians.
linearVelocity: (table) The linear velocity of the body's origin in world co-ordinates (see the example below to understand how this table is set).
angularVelocity: (number) The angular velocity of the body.
linearDamping: (number) Linear damping is use to reduce the linear velocity. The damping parameter can be larger than 1.0 but the damping effect becomes sensitive to the time step when the damping parameter is large.
angularDamping: (number) Angular damping is use to reduce the angular velocity. The damping parameter can be larger than 1.0 but the damping effect becomes sensitive to the time step when the damping parameter is large.
allowSleep: (boolean) Set this flag to false if this body should never fall asleep. Note that this increases CPU usage.
awake: (boolean) Is this body initially awake or sleeping?
fixedRotation: (boolean) Should this body be prevented from rotating? Useful for characters.
bullet: (boolean) Is this a fast moving body that should be prevented from tunneling through other moving bodies? Note that all bodies are prevented from tunneling through kinematic and static bodies. This setting is only considered on dynamic bodies. Warning: You should use this flag sparingly since it increases processing time.
active: (boolean) Does this body start out active?
gravityScale: (number) Scale the gravity applied to this body.

The unset fields gets default values.

Warning: This function is locked during callbacks.


(b2.Body) = b2.World:createBody(bodyDef)


Parameters

bodyDef: (table)


Return values

Returns (b2.Body) created body.

Examples

Example

local body = world:createBody{
	type = b2.STATIC_BODY,
	position = {x=0, y=0.5},
	angle = math.pi/4,
	linearVelocity = {x=0.1, y=0.2},
}