Difference between revisions of "B2.Body"
Line 2: | Line 2: | ||
'''Supported platforms:''' android, ios, mac, pc<br/> | '''Supported platforms:''' android, ios, mac, pc<br/> | ||
'''Available since:''' Gideros 2011.6<br/> | '''Available since:''' Gideros 2011.6<br/> | ||
− | === Description === | + | === <translate>Description</translate> === |
<translate><br /> | <translate><br /> | ||
A rigid body. These are created via [[Special:MyLanguage/b2.World:createBody|b2.World:createBody]].<br /> | A rigid body. These are created via [[Special:MyLanguage/b2.World:createBody|b2.World:createBody]].<br /> | ||
<br /></translate> | <br /></translate> | ||
− | === Examples === | + | === <translate>Examples</translate> === |
'''Creating Box2d body and moving Bitmap along the body'''<br/> | '''Creating Box2d body and moving Bitmap along the body'''<br/> | ||
<source lang="lua">require "box2d" | <source lang="lua">require "box2d" | ||
Line 39: | Line 39: | ||
{|- | {|- | ||
| style="width: 50%; vertical-align:top;"| | | style="width: 50%; vertical-align:top;"| | ||
− | === Methods === | + | === <translate>Methods</translate> === |
[[Special:MyLanguage/b2.Body:applyAngularImpulse|b2.Body:applyAngularImpulse]] ''<translate>applies an angular impulse</translate>''<br/> | [[Special:MyLanguage/b2.Body:applyAngularImpulse|b2.Body:applyAngularImpulse]] ''<translate>applies an angular impulse</translate>''<br/> | ||
[[Special:MyLanguage/b2.Body:applyForce|b2.Body:applyForce]] ''<translate>applies a force at a world point</translate>''<br/> | [[Special:MyLanguage/b2.Body:applyForce|b2.Body:applyForce]] ''<translate>applies a force at a world point</translate>''<br/> | ||
Line 79: | Line 79: | ||
[[Special:MyLanguage/b2.Body:setSleepingAllowed|b2.Body:setSleepingAllowed]] <br/> | [[Special:MyLanguage/b2.Body:setSleepingAllowed|b2.Body:setSleepingAllowed]] <br/> | ||
| style="width: 50%; vertical-align:top;"| | | style="width: 50%; vertical-align:top;"| | ||
− | === Events === | + | === <translate>Events</translate> === |
− | === Constants === | + | === <translate>Constants</translate> === |
|} | |} |
Revision as of 07:29, 24 August 2018
Supported platforms: android, ios, mac, pc
Available since: Gideros 2011.6
Description
A rigid body. These are created via b2.World:createBody.
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)
Methodsb2.Body:applyAngularImpulse applies an angular impulse |
EventsConstants |