Difference between revisions of "B2.World:createBody"

From GiderosMobile
m (Text replacement - "</source>" to "</syntaxhighlight>")
 
(8 intermediate revisions by 3 users not shown)
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><br />
+
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/>
&lt;ul&gt;<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/>
&lt;li&gt;**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.&lt;/li&gt;<br />
+
'''angle''': (number) The world angle of the body in radians.<br/>
&lt;li&gt;**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.&lt;/li&gt;<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/>
&lt;li&gt;**angle**: (number) The world angle of the body in radians.&lt;/li&gt;<br />
+
'''angularVelocity''': (number) The angular velocity of the body.<br/>
&lt;li&gt;**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).&lt;/li&gt;<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/>
&lt;li&gt;**angularVelocity**: (number) The angular velocity of the body.&lt;/li&gt;<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/>
&lt;li&gt;**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.&lt;/li&gt;<br />
+
'''allowSleep''': (boolean) Set this flag to false if this body should never fall asleep. Note that this increases CPU usage.<br/>
&lt;li&gt;**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.&lt;/li&gt;<br />
+
'''awake''': (boolean) Is this body initially awake or sleeping?<br/>
&lt;li&gt;**allowSleep**: (boolean) Set this flag to false if this body should never fall asleep. Note that this increases CPU usage.&lt;/li&gt;<br />
+
'''fixedRotation''': (boolean) Should this body be prevented from rotating? Useful for characters.<br/>
&lt;li&gt;**awake**: (boolean) Is this body initially awake or sleeping?&lt;/li&gt;<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/>
&lt;li&gt;**fixedRotation**: (boolean) Should this body be prevented from rotating? Useful for characters.&lt;/li&gt;<br />
+
'''active''': (boolean) Does this body start out active?<br/>
&lt;li&gt;**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.&lt;/li&gt;<br />
+
'''gravityScale''': (number) Scale the gravity applied to this body.<br/>
&lt;li&gt;**active**: (boolean) Does this body start out active?&lt;/li&gt;<br />
+
 
&lt;li&gt;**gravityScale**: (number) Scale the gravity applied to this body.&lt;/li&gt;<br />
+
The unset fields get default values.
&lt;/ul&gt;<br />
+
 
<br />
+
'''Warning:''' This function is locked during callbacks.
The unset fields gets default values.<br />
+
<syntaxhighlight lang="lua">
<br />
 
&lt;ul&gt;<br />
 
&lt;li&gt;*Warning:** This function is locked during callbacks.&lt;/li&gt;<br />
 
&lt;/ul&gt;<br />
 
<br /></translate>
 
<source lang="lua">
 
 
(b2.Body) = b2.World:createBody(bodyDef)
 
(b2.Body) = b2.World:createBody(bodyDef)
</source>
+
</syntaxhighlight>
 +
 
 
=== <translate>Parameters</translate> ===
 
=== <translate>Parameters</translate> ===
'''bodyDef''': (table) <translate></translate> <br/>
+
'''bodyDef''': (table) <translate></translate>
 +
 
 
=== <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/>
 +
 
=== <translate>Examples</translate> ===
 
=== <translate>Examples</translate> ===
'''Example'''<br/>
+
'''Example'''
<source lang="lua">local body = world:createBody{
+
<syntaxhighlight 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>
+
}
 +
</syntaxhighlight>
 +
 
 +
{{B2.World}}

Latest revision as of 14:26, 13 July 2023


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