Difference between revisions of "B2.World"
Line 1: | Line 1: | ||
__NOTOC__ | __NOTOC__ | ||
+ | <!-- GIDEROSOBJ:b2.World --> | ||
'''<translate>Supported platforms</translate>:''' [[File:Platform android.png]][[File:Platform ios.png]][[File:Platform mac.png]][[File:Platform pc.png]]<br/> | '''<translate>Supported platforms</translate>:''' [[File:Platform android.png]][[File:Platform ios.png]][[File:Platform mac.png]][[File:Platform pc.png]]<br/> | ||
'''<translate>Available since</translate>:''' Gideros 2011.6<br/> | '''<translate>Available since</translate>:''' Gideros 2011.6<br/> | ||
Line 89: | Line 90: | ||
| style="width: 50%; vertical-align:top;"| | | style="width: 50%; vertical-align:top;"| | ||
=== <translate>Methods</translate> === | === <translate>Methods</translate> === | ||
− | [[Special:MyLanguage/b2.World.new|b2.World.new]] <br/> | + | [[Special:MyLanguage/b2.World.new|b2.World.new]] <br/><!-- GIDEROSMTD:b2.World.new --> |
− | [[Special:MyLanguage/b2.World:clearForces|b2.World:clearForces]] ''<translate>call this after you are done with time steps to clear the forces</translate>''<br/> | + | [[Special:MyLanguage/b2.World:clearForces|b2.World:clearForces]] ''<translate>call this after you are done with time steps to clear the forces</translate>''<br/><!-- GIDEROSMTD:b2.World:clearForces --> |
− | [[Special:MyLanguage/b2.World:createBody|b2.World:createBody]] ''<translate>creates a rigid body given a definition</translate>''<br/> | + | [[Special:MyLanguage/b2.World:createBody|b2.World:createBody]] ''<translate>creates a rigid body given a definition</translate>''<br/><!-- GIDEROSMTD:b2.World:createBody --> |
− | [[Special:MyLanguage/b2.World:createJoint|b2.World:createJoint]] ''<translate>creates a joint given a definition</translate>''<br/> | + | [[Special:MyLanguage/b2.World:createJoint|b2.World:createJoint]] ''<translate>creates a joint given a definition</translate>''<br/><!-- GIDEROSMTD:b2.World:createJoint --> |
− | [[Special:MyLanguage/b2.World:createParticleSystem|b2.World:createParticleSystem]] ''<translate>create particle system</translate>''<br/> | + | [[Special:MyLanguage/b2.World:createParticleSystem|b2.World:createParticleSystem]] ''<translate>create particle system</translate>''<br/><!-- GIDEROSMTD:b2.World:createParticleSystem --> |
− | [[Special:MyLanguage/b2.World:destroyBody|b2.World:destroyBody]] ''<translate>destroys a rigid body</translate>''<br/> | + | [[Special:MyLanguage/b2.World:destroyBody|b2.World:destroyBody]] ''<translate>destroys a rigid body</translate>''<br/><!-- GIDEROSMTD:b2.World:destroyBody --> |
− | [[Special:MyLanguage/b2.World:destroyJoint|b2.World:destroyJoint]] ''<translate>destroys a joint</translate>''<br/> | + | [[Special:MyLanguage/b2.World:destroyJoint|b2.World:destroyJoint]] ''<translate>destroys a joint</translate>''<br/><!-- GIDEROSMTD:b2.World:destroyJoint --> |
− | [[Special:MyLanguage/b2.World:getGravity|b2.World:getGravity]] ''<translate>returns the gravity vector</translate>''<br/> | + | [[Special:MyLanguage/b2.World:getGravity|b2.World:getGravity]] ''<translate>returns the gravity vector</translate>''<br/><!-- GIDEROSMTD:b2.World:getGravity --> |
− | [[Special:MyLanguage/b2.World:queryAABB|b2.World:queryAABB]] ''<translate>query the world for all fixtures that potentially overlap the provided AABB</translate>''<br/> | + | [[Special:MyLanguage/b2.World:queryAABB|b2.World:queryAABB]] ''<translate>query the world for all fixtures that potentially overlap the provided AABB</translate>''<br/><!-- GIDEROSMTD:b2.World:queryAABB --> |
− | [[Special:MyLanguage/b2.World:rayCast|b2.World:rayCast]] ''<translate>raycast the world for all fixtures in the path of the ray</translate>''<br/> | + | [[Special:MyLanguage/b2.World:rayCast|b2.World:rayCast]] ''<translate>raycast the world for all fixtures in the path of the ray</translate>''<br/><!-- GIDEROSMTD:b2.World:rayCast --> |
− | [[Special:MyLanguage/b2.World:setDebugDraw|b2.World:setDebugDraw]] ''<translate>registers a b2.DebugDraw instance for debug drawing</translate>''<br/> | + | [[Special:MyLanguage/b2.World:setDebugDraw|b2.World:setDebugDraw]] ''<translate>registers a b2.DebugDraw instance for debug drawing</translate>''<br/><!-- GIDEROSMTD:b2.World:setDebugDraw --> |
− | [[Special:MyLanguage/b2.World:setGravity|b2.World:setGravity]] ''<translate>sets the gravity vector</translate>''<br/> | + | [[Special:MyLanguage/b2.World:setGravity|b2.World:setGravity]] ''<translate>sets the gravity vector</translate>''<br/><!-- GIDEROSMTD:b2.World:setGravity --> |
− | [[Special:MyLanguage/b2.World:step|b2.World:step]] ''<translate>takes a time step</translate>''<br/> | + | [[Special:MyLanguage/b2.World:step|b2.World:step]] ''<translate>takes a time step</translate>''<br/><!-- GIDEROSMTD:b2.World:step --> |
| style="width: 50%; vertical-align:top;"| | | style="width: 50%; vertical-align:top;"| | ||
=== <translate>Events</translate> === | === <translate>Events</translate> === | ||
− | [[Special:MyLanguage/Event.BEGIN_CONTACT|Event.BEGIN_CONTACT]]<br/> | + | [[Special:MyLanguage/Event.BEGIN_CONTACT|Event.BEGIN_CONTACT]]<br/><!-- GIDEROSEVT:Event.BEGIN_CONTACT --> |
− | [[Special:MyLanguage/Event.BEGIN_CONTACT_PARTICLE|Event.BEGIN_CONTACT_PARTICLE]]<br/> | + | [[Special:MyLanguage/Event.BEGIN_CONTACT_PARTICLE|Event.BEGIN_CONTACT_PARTICLE]]<br/><!-- GIDEROSEVT:Event.BEGIN_CONTACT_PARTICLE --> |
− | [[Special:MyLanguage/Event.END_CONTACT|Event.END_CONTACT]]<br/> | + | [[Special:MyLanguage/Event.END_CONTACT|Event.END_CONTACT]]<br/><!-- GIDEROSEVT:Event.END_CONTACT --> |
− | [[Special:MyLanguage/Event.POST_SOLVE|Event.POST_SOLVE]]<br/> | + | [[Special:MyLanguage/Event.POST_SOLVE|Event.POST_SOLVE]]<br/><!-- GIDEROSEVT:Event.POST_SOLVE --> |
− | [[Special:MyLanguage/Event.PRE_SOLVE|Event.PRE_SOLVE]]<br/> | + | [[Special:MyLanguage/Event.PRE_SOLVE|Event.PRE_SOLVE]]<br/><!-- GIDEROSEVT:Event.PRE_SOLVE --> |
=== <translate>Constants</translate> === | === <translate>Constants</translate> === | ||
|} | |} |
Revision as of 14:57, 31 August 2018
Supported platforms:
Available since: Gideros 2011.6
Inherits from: EventDispatcher
Description
The b2.World class inherits from the following class: EventDispatcher.
The b2.World class manages all physics entities and dynamic simulation. It is possible to create and manage more than one b2.World instance.
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)
Detecting collisions between bodies
--add collision event listener
world:addEventListener(Event.BEGIN_CONTACT, function(e)
--getting contact bodies
local fixtureA = e.fixtureA
local fixtureB = e.fixtureB
local bodyA = fixtureA:getBody()
local bodyB = fixtureB:getBody()
--do what you need with colliding bodies
end)
--add collision event listener
world:addEventListener(Event.END_CONTACT, function(e)
--getting contact bodies
local fixtureA = e.fixtureA
local fixtureB = e.fixtureB
local bodyA = fixtureA:getBody()
local bodyB = fixtureB:getBody()
--do what you need with colliding bodies
end)
--add collision event listener
world:addEventListener(Event.PRE_SOLVE, function(e)
--getting contact bodies
local fixtureA = e.fixtureA
local fixtureB = e.fixtureB
local bodyA = fixtureA:getBody()
local bodyB = fixtureB:getBody()
--do what you need with colliding bodies
end)
--add collision event listener
world:addEventListener(Event.POST_SOLVE, function(e)
--getting contact bodies
local fixtureA = e.fixtureA
local fixtureB = e.fixtureB
local bodyA = fixtureA:getBody()
local bodyB = fixtureB:getBody()
--do what you need with colliding bodies
--additionally get collision force
print(event.maxImpulse)
end)
Methodsb2.World.new |
EventsEvent.BEGIN_CONTACT Constants |