Difference between revisions of "B2.Body"
(removed language stuff) |
|||
Line 76: | Line 76: | ||
[[b2.Body:setBullet]] <br/><!-- GIDEROSMTD:b2.Body:setBullet(flag) --> | [[b2.Body:setBullet]] <br/><!-- GIDEROSMTD:b2.Body:setBullet(flag) --> | ||
[[b2.Body:setFixedRotation]] <br/><!-- GIDEROSMTD:b2.Body:setFixedRotation(flag) --> | [[b2.Body:setFixedRotation]] <br/><!-- GIDEROSMTD:b2.Body:setFixedRotation(flag) --> | ||
− | [[b2.Body:setGravityScale]] '' | + | [[b2.Body:setGravityScale]] ''strengthens or weakens the effect of the world gravity on a body''<br/><!-- GIDEROSMTD:b2.Body:setGravityScale(scale) strengthens or weakens the effect of the world gravity on a body--> |
[[b2.Body:setLinearDamping]] ''sets the linear damping of the body''<br/><!-- GIDEROSMTD:b2.Body:setLinearDamping(linearDamping) sets the linear damping of the body --> | [[b2.Body:setLinearDamping]] ''sets the linear damping of the body''<br/><!-- GIDEROSMTD:b2.Body:setLinearDamping(linearDamping) sets the linear damping of the body --> | ||
[[b2.Body:setLinearVelocity]] ''sets the linear velocity of the center of mass''<br/><!-- GIDEROSMTD:b2.Body:setLinearVelocity(x,y) sets the linear velocity of the center of mass --> | [[b2.Body:setLinearVelocity]] ''sets the linear velocity of the center of mass''<br/><!-- GIDEROSMTD:b2.Body:setLinearVelocity(x,y) sets the linear velocity of the center of mass --> | ||
Line 83: | Line 83: | ||
| style="width: 50%; vertical-align:top;"| | | style="width: 50%; vertical-align:top;"| | ||
+ | |||
=== Events === | === Events === | ||
=== Constants === | === Constants === |
Revision as of 04:10, 28 November 2021
Supported platforms:
Available since: Gideros 2011.6
Description
A rigid body 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 |