Difference between revisions of "love.physics.newBody"

(Added warning to not call during callbacks)
(4 intermediate revisions by 3 users not shown)
Line 1: Line 1:
Create a new body.
+
Creates a new body.
A body with zero mass is '''static''' and will not move.
+
 
Mass can be changed at any time with [[Body:setMass]] or [[Body:setMassFromShapes]].
+
There are three types of bodies.
 +
* Static bodies do not move, have a infinite mass, and can be used for level boundaries.
 +
* Dynamic bodies are the main actors in the simulation, they collide with everything.
 +
* Kinematic bodies do not react to forces and only collide with dynamic bodies.
 +
 
 +
The mass of the body gets calculated when a [[Fixture]] is attached or removed, but can be changed at any time with [[Body:setMass]] or [[Body:resetMassData]].
 +
 
 +
{{notice|Making changes to a [[World]] is not allowed inside of the [[beginContact]], [[endContact]], [[preSolve]], and [[postSolve]] callback functions, as BOX2D locks the world during these callbacks.}}
  
 
== Function ==
 
== Function ==
 +
{{newin|[[0.8.0]]|080|type=variant}}
 
=== Synopsis ===
 
=== Synopsis ===
 
<source lang="lua">
 
<source lang="lua">
body = love.physics.newBody( world, x, y, m, i )
+
body = love.physics.newBody( world, x, y, type )
 
</source>
 
</source>
 
=== Arguments ===
 
=== Arguments ===
Line 12: Line 20:
 
{{param|number|x (0)|The x position of the body.}}
 
{{param|number|x (0)|The x position of the body.}}
 
{{param|number|y (0)|The y position of the body.}}
 
{{param|number|y (0)|The y position of the body.}}
{{param|number|m (0)|The mass of the body.}}
+
{{param|BodyType|type ("static")|The type of the body.}}
{{param|number|i (0)|The rotational inertia of the body.}}
 
 
=== Returns ===
 
=== Returns ===
 
{{param|Body|body|A new body.}}
 
{{param|Body|body|A new body.}}
----
+
 
{{newin|[[0.8.0]]|type=variants|plural=y}}
 
 
== Function ==
 
== Function ==
 +
{{oldin|[[0.8.0]]|080|type=variant}}
 
=== Synopsis ===
 
=== Synopsis ===
 
<source lang="lua">
 
<source lang="lua">
body = love.physics.newBody( world, x, y, type )
+
body = love.physics.newBody( world, x, y, m, i )
 
</source>
 
</source>
 
=== Arguments ===
 
=== Arguments ===
Line 27: Line 34:
 
{{param|number|x (0)|The x position of the body.}}
 
{{param|number|x (0)|The x position of the body.}}
 
{{param|number|y (0)|The y position of the body.}}
 
{{param|number|y (0)|The y position of the body.}}
{{param|string|type|Whether the body is static or dynamic.}}
+
{{param|number|m (0)|The mass of the body.}}
 +
{{param|number|i (0)|The rotational inertia of the body.}}
 
=== Returns ===
 
=== Returns ===
 
{{param|Body|body|A new body.}}
 
{{param|Body|body|A new body.}}
----
+
 
 
== See Also ==
 
== See Also ==
 
* [[parent::love.physics]]
 
* [[parent::love.physics]]
 
* [[Constructs::Body]]
 
* [[Constructs::Body]]
 
[[Category:Functions]]
 
[[Category:Functions]]
{{#set:Description=Create a new body.}}
+
{{#set:Description=Creates a new body.}}
 
{{#set:Since=000}}
 
{{#set:Since=000}}
 
== Other Languages ==
 
== Other Languages ==
 
{{i18n|love.physics.newBody}}
 
{{i18n|love.physics.newBody}}

Revision as of 07:46, 14 October 2018

Creates a new body.

There are three types of bodies.

  • Static bodies do not move, have a infinite mass, and can be used for level boundaries.
  • Dynamic bodies are the main actors in the simulation, they collide with everything.
  • Kinematic bodies do not react to forces and only collide with dynamic bodies.

The mass of the body gets calculated when a Fixture is attached or removed, but can be changed at any time with Body:setMass or Body:resetMassData.

O.png Making changes to a World is not allowed inside of the beginContact, endContact, preSolve, and postSolve callback functions, as BOX2D locks the world during these callbacks.  


Function

Available since LÖVE 0.8.0
This variant is not supported in earlier versions.

Synopsis

body = love.physics.newBody( world, x, y, type )

Arguments

World world
The world to create the body in.
number x (0)
The x position of the body.
number y (0)
The y position of the body.
BodyType type ("static")
The type of the body.

Returns

Body body
A new body.

Function

Removed in LÖVE 0.8.0
This variant is not supported in that and later versions.

Synopsis

body = love.physics.newBody( world, x, y, m, i )

Arguments

World world
The world to create the body in.
number x (0)
The x position of the body.
number y (0)
The y position of the body.
number m (0)
The mass of the body.
number i (0)
The rotational inertia of the body.

Returns

Body body
A new body.

See Also


Other Languages