Difference between revisions of "B2.World:step"

From GiderosMobile
m (Text replacement - "</source>" to "</syntaxhighlight>")
 
(8 intermediate revisions by 3 users not shown)
Line 1: Line 1:
 
__NOTOC__
 
__NOTOC__
'''Available since:''' Gideros 2011.6<br/>
+
<languages />
=== Description ===
+
'''<translate>Available since</translate>:''' Gideros 2011.6<br/>
<br />
+
'''<translate>Class</translate>:''' [[Special:MyLanguage/b2.World|b2.World]]<br/>
Take a time step. This performs collision detection, integration, and constraint solution.<br />
+
 
<br />
+
=== <translate>Description</translate> ===
<source lang="lua">
+
Takes a time step. This performs collision detection, integration, and constraint solution.
b2.World:step(timeStep,velocityIterations,positionIterations)
+
<syntaxhighlight lang="lua">
</source>
+
b2.World:step(timeStep,velocityIterations,positionIterations)
'''timeStep''': (number) the amount of time to simulate, this should not vary ''''''<br/>
+
</syntaxhighlight>
'''velocityIterations''': (number) for the velocity constraint solver ''''''<br/>
+
 
'''positionIterations''': (number) for the position constraint solver ''''''<br/>
+
=== <translate>Parameters</translate> ===
 +
'''timeStep''': (number) <translate>the amount of time to simulate, this should not vary</translate> <br/>
 +
'''velocityIterations''': (number) <translate>for the velocity constraint solver</translate> <br/>
 +
'''positionIterations''': (number) <translate>for the position constraint solver</translate> <br/>
 +
 
 +
=== <translate>Examples</translate> ===
 +
'''Creating Box2d body and moving Bitmap along the body'''
 +
<syntaxhighlight lang="lua">
 +
require "box2d"
 +
local world = b2.World.new(0, 10, true)
 +
 
 +
--create ball bitmap object from ball graphic
 +
local ball = Bitmap.new(Texture.new("ball.png"))
 +
--reference center of the ball for positioning
 +
ball:setAnchorPoint(0.5,0.5)
 +
 +
ball:setPosition(100,100)
 +
 +
--get radius
 +
local radius = ball:getWidth()/2
 +
 +
--create box2d physical object
 +
local body = world:createBody{type = b2.DYNAMIC_BODY}
 +
local circle = b2.CircleShape.new(0, 0, radius)
 +
local fixture = body:createFixture{shape = circle, density = 1.0,
 +
friction = 0.1, restitution = 0.2}
 +
ball.body = body
 +
 +
--add to scene
 +
stage:addChild(ball)
 +
 
 +
stage:addEventListener(Event.ENTER_FRAME, function()
 +
-- edit the step values if required. These are good defaults!
 +
    world:step(1/60, 8, 3)
 +
ball:setPosition(ball.body:getPosition())
 +
ball:setRotation(math.rad(ball.body:getAngle()))
 +
end)
 +
</syntaxhighlight>
 +
 
 +
{{B2.World}}

Latest revision as of 15:27, 13 July 2023


Available since: Gideros 2011.6
Class: b2.World

Description

Takes a time step. This performs collision detection, integration, and constraint solution.

b2.World:step(timeStep,velocityIterations,positionIterations)

Parameters

timeStep: (number) the amount of time to simulate, this should not vary
velocityIterations: (number) for the velocity constraint solver
positionIterations: (number) for the position constraint solver

Examples

Creating Box2d body and moving Bitmap along the body

require "box2d"
local world = b2.World.new(0, 10, true)

--create ball bitmap object from ball graphic
local ball = Bitmap.new(Texture.new("ball.png"))
--reference center of the ball for positioning
ball:setAnchorPoint(0.5,0.5)
 
ball:setPosition(100,100)
 
--get radius
local radius = ball:getWidth()/2
 
--create box2d physical object
local body = world:createBody{type = b2.DYNAMIC_BODY}
local circle = b2.CircleShape.new(0, 0, radius)
local fixture = body:createFixture{shape = circle, density = 1.0, 
friction = 0.1, restitution = 0.2}
ball.body = body
 
--add to scene
stage:addChild(ball)

stage:addEventListener(Event.ENTER_FRAME, function()
	-- edit the step values if required. These are good defaults!
    world:step(1/60, 8, 3)
	ball:setPosition(ball.body:getPosition())
	ball:setRotation(math.rad(ball.body:getAngle()))
end)





LiquidFun