1 package{ 2 import Box2D.Common.Math.b2Vec2; 3 import Box2D.Dynamics.b2Body; 4 import Box2D.Dynamics.Joints.b2LineJointDef; 5 import Box2D.Dynamics.Joints.b2PrismaticJointDef; 6 7 /** 8 * 线关节,限制一个刚体只能在一个轴向上移动 9 */ 10 public class Main extends BaseMain{ 11 12 13 public function Main(){ 14 super(new b2Vec2(0,10)); 15 } 16 17 override protected function init():void{ 18 var bodyA:b2Body=this.createBox(50,50,400,300); 19 var bodyB:b2Body=this.createCircle(25,400,300); 20 bodyA.SetType(b2Body.b2_staticBody); 21 22 var jointDef:b2LineJointDef=new b2LineJointDef(); 23 var anchor:b2Vec2=bodyA.GetWorldCenter(); 24 var axis:b2Vec2=new b2Vec2(1,0); 25 jointDef.Initialize(bodyA,bodyB,anchor,axis); 26 _world.CreateJoint(jointDef); 27 28 } 29 30 31 }; 32 }
源码下载:http://yunpan.cn/c37xzDJTk4ekb 访问密码 c8c5