#rem
In this demo I create two bodies and then join them with a Joint.
one body is a static body.
Please take this demo and expend it with explanations so we can all learn. (keep it simple..)
#End
'----Imports----'
Import box2d.collision
Import box2d.collision.shapes
Import box2d.common.math
Import box2d.dynamics.contacts
Import box2d.dynamics
Import box2d.flash.flashtypes
Import box2d.common.math.b2vec2
'----Test Zone----'
Function Main()
New Box2DLoop
End Function
'----Main Loop----'
Class Box2DLoop Extends App
'Box 2D World Definitions
Field BXworld : b2World 'Box2D physical World Object
Field m_velocityIterations : Int = 10 'Dont know whats this yet.
Field m_positionIterations : Int = 10 'Either that.
Field m_timeStep : Float = 1.0/60 'Hmm, I know whats this but no changes accured when presetting.
Field m_physScale : Float = 1 ' 30 'I Change its value but same results.
Field m_debugdrawscale : Float = 10 'This Affects the size of the physical Body Display
'A Box2D Object Definition
Field ABody:b2Body 'The Actual Body
Field BBody:b2Body 'The Actual Body
Field BodyDef:b2BodyDef
Field BodyShape:b2PolygonShape
Field BodyFixture:b2FixtureDef
Method OnCreate()
'Display Setup
SetUpdateRate(60)
'--Box2D Section--'
'World Setups
BXworld = New b2World(New b2Vec2(0,9.7),True)
'General Body Definitions
BodyDef =New b2BodyDef
BodyShape =New b2PolygonShape()
BodyFixture=New b2FixtureDef
BodyDef.type=b2Body.b2_Body 'A dynamic body set
BodyFixture.density =1.0
BodyFixture.friction =0.5
BodyFixture.restitution =0.1
BodyShape.SetAsBox(5,5)
BodyFixture.shape=BodyShape
'Create Body 1
ABody=BXworld.CreateBody(BodyDef)
ABody.CreateFixture(BodyFixture)
ABody.SetPosition(New b2Vec2(20,20))
'Create Body 2
BBody=BXworld.CreateBody(BodyDef)
BBody.CreateFixture(BodyFixture)
BBody.SetPosition(New b2Vec2(45,20))
BBody.SetType(True) 'Setting the Body as Static
'------------------------------------------------------------'
'Basic Creation of Joint type revolute..
Local NewJoint:b2RevoluteJointDef=New b2RevoluteJointDef
NewJoint.Initialize(ABody,BBody,New b2Vec2(30.0,25.0))
BXworld.CreateJoint(NewJoint)
'------------------------------------------------------------'
'Debug Settings 'Delete this section if you dont need to see the physical process.
Local dbgDraw :b2DebugDraw = New b2DebugDraw()
dbgDraw.SetDrawScale(m_debugdrawscale)
dbgDraw.SetFillAlpha(0.3)
dbgDraw.SetLineThickness(1.0)
dbgDraw.SetFlags(b2DebugDraw.e_shapeBit | b2DebugDraw.e_jointBit)'| b2DebugDraw.e_pairBit)
BXworld.SetDebugDraw(dbgDraw)
End Method
Method OnRender()
Cls
'Box2D Display Section
BXworld.DrawDebugData() 'Delete this line if you dont need to see the physical process in graphics. (must also delete 'Box2D Debug Settings section above)
End Method
Method OnUpdate()
'The Stepping of Box2D Engine
BXworld.TimeStep(m_timeStep,m_velocityIterations,m_positionIterations)
BXworld.ClearForces() 'Dont know why you need this..
End Method
End Class
This website uses cookies to improve your experience while you navigate through the website. Out of these, the cookies that are categorized as necessary are stored on your browser as they are essential for the working of basic functionalities of the website. We also use third-party cookies that help us analyze and understand how you use this website. These cookies will be stored in your browser only with your consent. You also have the option to opt-out of these cookies. But opting out of some of these cookies may affect your browsing experience.
Necessary cookies are absolutely essential for the website to function properly. This category only includes cookies that ensures basic functionalities and security features of the website. These cookies do not store any personal information.
Any cookies that may not be particularly necessary for the website to function and is used specifically to collect user personal data via analytics, ads, other embedded contents are termed as non-necessary cookies. It is mandatory to procure user consent prior to running these cookies on your website.