Difference between revisions of "love.physics.newBody"

(direct translation, free translation at few places)
 
(8 intermediate revisions by 6 users not shown)
Line 1: Line 1:
Vytvoří fyzikální těleso.
+
Creates a new body.
  
Pokud je hmota 0, tak je těleso '''nehybné'''. Hmota se dá měnit kdykoli pomocí [[Body:setMass_(Česky)|Body:setMass]] či [[Body:setMassFromShapes_(Česky)|Body:setMassFromShapes]].
+
There are three types of bodies.
 +
* Static bodies do not move, have an 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.
  
== Funkce ==
+
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]].
=== Zápis ===
+
 
 +
{{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 ==
 +
{{newin|[[0.8.0]]|080|type=variant}}
 +
=== Synopsis ===
 +
<source lang="lua">
 +
body = love.physics.newBody( world, x, y, type )
 +
</source>
 +
=== Arguments ===
 +
{{param|World|world|The world to create the body in.}}
 +
{{param|number|x (0)|The x position of the body.}}
 +
{{param|number|y (0)|The y position of the body.}}
 +
{{param|BodyType|type ("static")|The type of the body.}}
 +
=== Returns ===
 +
{{param|Body|body|A new body.}}
 +
 
 +
== Function ==
 +
{{oldin|[[0.8.0]]|080|type=variant}}
 +
=== Synopsis ===
 
<source lang="lua">
 
<source lang="lua">
 
body = love.physics.newBody( world, x, y, m, i )
 
body = love.physics.newBody( world, x, y, m, i )
 
</source>
 
</source>
=== Argumenty ===
+
=== Arguments ===
{{param|World_(Česky)|world|Svět ve kterém se těleso vytvoří.}}
+
{{param|World|world|The world to create the body in.}}
{{param|number_(Česky)|x (0)|Pozice x tělesa.}}
+
{{param|number|x (0)|The x position of the body.}}
{{param|number_(Česky)|y (0)|Pozice y tělesa.}}
+
{{param|number|y (0)|The y position of the body.}}
{{param|number_(Česky)|m (0)|Hmota tělesa.}}
+
{{param|number|m (0)|The mass of the body.}}
{{param|number_(Česky)|i (0)|Moment setrvačnosti tělesa.}}
+
{{param|number|i (0)|The rotational inertia of the body.}}
=== Vrací ===
+
=== Returns ===
{{param|Body_(Česky)|body|Nové těleso.}}
+
{{param|Body|body|A new body.}}
== Dále ==
+
 
* [[parent::love.physics_(Česky)]]
+
== Examples ==
* [[Constructs::Body_(Česky)]]
+
<source lang="lua">
 +
love.physics.setMeter(40) -- meter is 40 px/units
 +
world = love.physics.newWorld(0, 9.81*40, true) -- new world with gravity
 +
body1 = love.physics.newBody(world, 250, 300, "static") -- new static body at x=250, y=300
 +
body2 = love.physics.newBody(world, 251, 100, "dynamic") -- new dynamic body at x=251, y=100
 +
</source>
 +
 
 +
== See Also ==
 +
* [[parent::love.physics]]
 +
* [[Constructs::Body]]
 
[[Category:Functions]]
 
[[Category:Functions]]
{{#set:Description=Vytvoří fyzikální těleso.}}
+
{{#set:Description=Creates a new body.}}
 
{{#set:Since=000}}
 
{{#set:Since=000}}
== Překlady ==
+
== Other Languages ==
 
{{i18n|love.physics.newBody}}
 
{{i18n|love.physics.newBody}}

Latest revision as of 18:24, 19 April 2022

Creates a new body.

There are three types of bodies.

  • Static bodies do not move, have an 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.

Examples

love.physics.setMeter(40) -- meter is 40 px/units
world = love.physics.newWorld(0, 9.81*40, true) -- new world with gravity
body1 = love.physics.newBody(world, 250, 300, "static") -- new static body at x=250, y=300
body2 = love.physics.newBody(world, 251, 100, "dynamic") -- new dynamic body at x=251, y=100

See Also


Other Languages