Difference between revisions of "B2.World:createBody"

From GiderosMobile
Line 3: Line 3:
 
'''<translate>Available since</translate>:''' Gideros 2011.6<br/>
 
'''<translate>Available since</translate>:''' Gideros 2011.6<br/>
 
'''<translate>Class</translate>:''' [[Special:MyLanguage/b2.World|b2.World]]<br/>
 
'''<translate>Class</translate>:''' [[Special:MyLanguage/b2.World|b2.World]]<br/>
 +
 
=== <translate>Description</translate> ===
 
=== <translate>Description</translate> ===
<translate>
+
Creates a rigid body given a definition. The body definition is given as an ordinary table. The fields of the body definition table are:
Creates a rigid body given a definition. The body definition is given as an ordinary table. The fields of the body definition table are:<br />
+
 
<br />
+
'''type''': (number) The body type: [[Special:MyLanguage/b2.STATIC_BODY|b2.STATIC_BODY]], [[Special:MyLanguage/b2.KINEMATIC_BODY|b2.KINEMATIC_BODY]], or [[Special:MyLanguage/b2.DYNAMIC_BODY|b2.DYNAMIC_BODY]]. Note: if a dynamic body would have zero mass, the mass is set to one.<br/>
'''type''': (number) The body type: [[Special:MyLanguage/b2.STATIC_BODY|b2.STATIC_BODY]], [[Special:MyLanguage/b2.KINEMATIC_BODY|b2.KINEMATIC_BODY]], or [[Special:MyLanguage/b2.DYNAMIC_BODY|b2.DYNAMIC_BODY]]. Note: if a dynamic body would have zero mass, the mass is set to one.<br />
+
'''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.<br/>
'''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.<br />
+
'''angle''': (number) The world angle of the body in radians.<br/>
'''angle''': (number) The world angle of the body in radians.<br />
+
'''linearVelocity''': (table) The linear velocity of the body origin in world co-ordinates (see the example below to understand how this table is set).<br/>
'''linearVelocity''': (table) The linear velocity of the body&#039;s origin in world co-ordinates (see the example below to understand how this table is set).<br />
+
'''angularVelocity''': (number) The angular velocity of the body.<br/>
'''angularVelocity''': (number) The angular velocity of the body.<br />
+
'''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.<br/>
'''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.<br />
+
'''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.<br/>
'''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.<br />
+
'''allowSleep''': (boolean) Set this flag to false if this body should never fall asleep. Note that this increases CPU usage.<br/>
'''allowSleep''': (boolean) Set this flag to false if this body should never fall asleep. Note that this increases CPU usage.<br />
+
'''awake''': (boolean) Is this body initially awake or sleeping?<br/>
'''awake''': (boolean) Is this body initially awake or sleeping?<br />
+
'''fixedRotation''': (boolean) Should this body be prevented from rotating? Useful for characters.<br/>
'''fixedRotation''': (boolean) Should this body be prevented from rotating? Useful for characters.<br />
+
'''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.<br/>
'''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.<br />
+
'''active''': (boolean) Does this body start out active?<br/>
'''active''': (boolean) Does this body start out active?<br />
+
'''gravityScale''': (number) Scale the gravity applied to this body.<br/>
'''gravityScale''': (number) Scale the gravity applied to this body.<br />
+
 
<br />
+
The unset fields get default values.
The unset fields gets default values.<br />
 
<br />
 
'''Warning:''' This function is locked during callbacks.<br />
 
  
<br /></translate>
+
'''Warning:''' This function is locked during callbacks.
 
<source lang="lua">
 
<source lang="lua">
 
(b2.Body) = b2.World:createBody(bodyDef)
 
(b2.Body) = b2.World:createBody(bodyDef)
 
</source>
 
</source>
<br />
+
 
 
=== <translate>Parameters</translate> ===
 
=== <translate>Parameters</translate> ===
 
'''bodyDef''': (table) <translate></translate>
 
'''bodyDef''': (table) <translate></translate>
<br/>
 
  
 
=== <translate>Return values</translate> ===
 
=== <translate>Return values</translate> ===
 
'''<translate>Returns</translate>''' (b2.Body) <translate>created body.</translate><br/>
 
'''<translate>Returns</translate>''' (b2.Body) <translate>created body.</translate><br/>
<br />
+
 
 
=== <translate>Examples</translate> ===
 
=== <translate>Examples</translate> ===
'''Example'''<br/>
+
'''Example'''
<source lang="lua">local body = world:createBody{
+
<source lang="lua">
 +
local body = world:createBody{
 
type = b2.STATIC_BODY,
 
type = b2.STATIC_BODY,
 
position = {x=0, y=0.5},
 
position = {x=0, y=0.5},
 
angle = math.pi/4,
 
angle = math.pi/4,
 
linearVelocity = {x=0.1, y=0.2},
 
linearVelocity = {x=0.1, y=0.2},
}</source>
+
}
 +
</source>
 +
 
 +
{{B2.World}}

Revision as of 16:54, 18 February 2020


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 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 get 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},
}





LiquidFun