Game Development Reference
In-Depth Information
6.
The following is how your Main function should look now:
public function Main() {
world=new b2World(new b2Vec2(0,9.81),true);
var bodyDef:b2BodyDef=new b2BodyDef();
bodyDef.position.Set(320/worldScale,30/worldScale);
var circleShape:b2CircleShape;
circleShape=new b2CircleShape(25/worldScale);
var fixtureDef:b2FixtureDef=new b2FixtureDef();
fixtureDef.shape=circleShape;
var theBall:b2Body=world.CreateBody(bodyDef);
theBall.CreateFixture(fixtureDef);
bodyDef.position.Set(320/worldScale,470/worldScale);
var polygonShape:b2PolygonShape=new b2PolygonShape();
polygonShape.SetAsBox(320/worldScale,10/worldScale);
fixtureDef.shape=polygonShape;
var theFloor:b2Body=world.CreateBody(bodyDef);
theFloor.CreateFixture(fixtureDef);
var debugDraw:b2DebugDraw=new b2DebugDraw();
var debugSprite:Sprite=new Sprite();
addChild(debugSprite);
debugDraw.SetSprite(debugSprite);
debugDraw.SetDrawScale(worldScale);
debugDraw.SetFlags(b2DebugDraw.e_shapeBit);
debugDraw.SetFillAlpha(0.5);
world.SetDebugDraw(debugDraw);
addEventListener(Event.ENTER_FRAME,updateWorld);
}
7.
Test the movie and you'll see the floor:
 
Search WWH ::




Custom Search