Game Development Reference
In-Depth Information
body3.SetLinearVelocity(new b2Vec2(100,-10));
stage.addEventListener(MouseEvent.CLICK,updateWorld);
}
Why are we making the barrier static? As it's a sensor, its collision won't
be solved, so if we set it as dynamic it won't collide with the ground,
falling down. Making it static will ensure us it will stay in its place.
3.
Finally, we modify the updateWorld function in the same way you
already learned when you worked on collision detection:
private function updateWorld(e:MouseEvent):void {
world.Step(1/30,10,10);
world.ClearForces();
for (var b:b2Body=world.GetBodyList();b; b=b.GetNext()) {
for (var c:b2ContactEdge=b.GetContactList();c; c=c.next) {
var contact:b2Contact=c.contact;
var fixtureA:b2Fixture=contact.GetFixtureA();
var fixtureB:b2Fixture=contact.GetFixtureB();
var bodyA:b2Body=fixtureA.GetBody();
var bodyB:b2Body=fixtureB.GetBody();
var userDataA:String=bodyA.GetUserData();
var userDataB:String=bodyB.GetUserData();
if (userDataA=="barrier" || userDataB=="barrier") {
trace(userDataA+"->"+userDataB);
}
}
}
world.DrawDebugData();
}
4.
We scan through all bodies, and for each body through all contacts,
and when we find the barrier is colliding with something, we write in
the output window about what happened.
 
Search WWH ::




Custom Search