Game Development Reference
In-Depth Information
In my experience, I had to set as bullets only some particles and projectiles fired by
players or enemies. Normally game characters do not move that fast to require them
to be set as bullets.
1.
Change the Main function by adding the highlighted line:
public function Main() {
world=new b2World(new b2Vec2(0,5),true);
debugDraw();
var bodyDef:b2BodyDef=new b2BodyDef();
bodyDef.position.Set(320/worldScale,470/worldScale);
var polygonShape:b2PolygonShape=new b2PolygonShape();
polygonShape.SetAsBox(320/worldScale,10/worldScale);
var fixtureDef:b2FixtureDef=new b2FixtureDef();
fixtureDef.shape=polygonShape;
fixtureDef.density=1;
fixtureDef.restitution=0.5;
fixtureDef.friction=0.5;
var body:b2Body=world.CreateBody(bodyDef);
body.CreateFixture(fixtureDef);
bodyDef.position.Set(600/worldScale,240/worldScale);
bodyDef.type=b2Body.b2_dynamicBody;
polygonShape.SetAsBox(10/worldScale,220/worldScale);
var body2:b2Body=world.CreateBody(bodyDef);
body2.CreateFixture(fixtureDef);
bodyDef.position.Set(320/worldScale,455/worldScale);
bodyDef.bullet=true;
polygonShape.SetAsBox(5/worldScale,5/worldScale);
var body3:b2Body=world.CreateBody(bodyDef);
body3.CreateFixture(fixtureDef);
body3.SetLinearVelocity(new b2Vec2(100,-10));
stage.addEventListener(MouseEvent.CLICK,updateWorld);
}
Setting the bullet property in the body definition to true will enable
continuous collision detection to the bullet. Now the bullet should
bounce
on the barrier.
 
Search WWH ::




Custom Search