Difference between revisions of "B2.Body"
Line 54: | Line 54: | ||
[[b2.Body:getLinearVelocity]] ''<translate>returns the linear velocity of the center of mass</translate>''<br/> | [[b2.Body:getLinearVelocity]] ''<translate>returns the linear velocity of the center of mass</translate>''<br/> | ||
[[b2.Body:getLocalCenter]] ''<translate>returns the local position of the center of mass</translate>''<br/> | [[b2.Body:getLocalCenter]] ''<translate>returns the local position of the center of mass</translate>''<br/> | ||
− | [[b2.Body:getLocalPoint]] | + | [[b2.Body:getLocalPoint]] <br/> |
− | [[b2.Body:getLocalVector]] | + | [[b2.Body:getLocalVector]] <br/> |
[[b2.Body:getMass]] ''<translate>returns the total mass of the body in kilograms (kg)</translate>''<br/> | [[b2.Body:getMass]] ''<translate>returns the total mass of the body in kilograms (kg)</translate>''<br/> | ||
[[b2.Body:getPosition]] ''<translate>returns the world body origin position</translate>''<br/> | [[b2.Body:getPosition]] ''<translate>returns the world body origin position</translate>''<br/> | ||
[[b2.Body:getWorldCenter]] ''<translate>returns the world position of the center of mass</translate>''<br/> | [[b2.Body:getWorldCenter]] ''<translate>returns the world position of the center of mass</translate>''<br/> | ||
− | [[b2.Body:getWorldPoint]] | + | [[b2.Body:getWorldPoint]] <br/> |
− | [[b2.Body:getWorldVector]] | + | [[b2.Body:getWorldVector]] <br/> |
[[b2.Body:isActive]] ''<translate>returns the active state of the body</translate>''<br/> | [[b2.Body:isActive]] ''<translate>returns the active state of the body</translate>''<br/> | ||
[[b2.Body:isAwake]] ''<translate>returns the sleeping state of the body</translate>''<br/> | [[b2.Body:isAwake]] ''<translate>returns the sleeping state of the body</translate>''<br/> | ||
− | [[b2.Body:isBullet]] | + | [[b2.Body:isBullet]] <br/> |
− | [[b2.Body:isFixedRotation]] | + | [[b2.Body:isFixedRotation]] <br/> |
− | [[b2.Body:isSleepingAllowed]] | + | [[b2.Body:isSleepingAllowed]] <br/> |
[[b2.Body:setActive]] ''<translate>sets the active state of the body</translate>''<br/> | [[b2.Body:setActive]] ''<translate>sets the active state of the body</translate>''<br/> | ||
− | [[b2.Body:setAngle]] | + | [[b2.Body:setAngle]] <br/> |
[[b2.Body:setAngularDamping]] ''<translate>sets the angular damping of the body</translate>''<br/> | [[b2.Body:setAngularDamping]] ''<translate>sets the angular damping of the body</translate>''<br/> | ||
[[b2.Body:setAngularVelocity]] ''<translate>sets the angular velocity</translate>''<br/> | [[b2.Body:setAngularVelocity]] ''<translate>sets the angular velocity</translate>''<br/> | ||
[[b2.Body:setAwake]] ''<translate>sets the sleep state of the body</translate>''<br/> | [[b2.Body:setAwake]] ''<translate>sets the sleep state of the body</translate>''<br/> | ||
− | [[b2.Body:setBullet]] | + | [[b2.Body:setBullet]] <br/> |
− | [[b2.Body:setFixedRotation]] | + | [[b2.Body:setFixedRotation]] <br/> |
[[b2.Body:setGravityScale]] ''<translate>sets the gravity scale of the body</translate>''<br/> | [[b2.Body:setGravityScale]] ''<translate>sets the gravity scale of the body</translate>''<br/> | ||
[[b2.Body:setLinearDamping]] ''<translate>sets the linear damping of the body</translate>''<br/> | [[b2.Body:setLinearDamping]] ''<translate>sets the linear damping of the body</translate>''<br/> | ||
[[b2.Body:setLinearVelocity]] ''<translate>sets the linear velocity of the center of mass</translate>''<br/> | [[b2.Body:setLinearVelocity]] ''<translate>sets the linear velocity of the center of mass</translate>''<br/> | ||
[[b2.Body:setPosition]] ''<translate>sets the world body origin position</translate>''<br/> | [[b2.Body:setPosition]] ''<translate>sets the world body origin position</translate>''<br/> | ||
− | [[b2.Body:setSleepingAllowed]] | + | [[b2.Body:setSleepingAllowed]] <br/> |
| style="width: 50%; vertical-align:top;"| | | style="width: 50%; vertical-align:top;"| | ||
=== Events === | === Events === | ||
=== Constants === | === Constants === | ||
|} | |} |
Revision as of 14:35, 23 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 |