Game Development Reference
In-Depth Information
levelFailed();
}
}
}
}
}
world.DrawDebugData();
}
And the core of the script lies in the following line:
for (var c:b2ContactEdge=b.GetContactList(); c; c=c.next) {
With the same concept applied to the GetBodyList method to scan through
all bodies in the Box2D world, GetContactList allows us to scan through all
contacts of a single body, in this case the idol, as this loop is executed only if
we are dealing with the idol.
b2ContactEdge is used to connect bodies and contacts together, and as we
are looking for the contacts, we must retrieve for each b2ContactEdge object
the b2Contact object, which we are so used to working with now. So we will
gain access to the contact in the following way:
var contact:b2Contact=c.contact;
At this time, the loop is very similar to the callback functions explained at the
beginning of the chapter. I also wrote the code in the same way to let you see
it's the same concept, although in this case the following code:
if (userDataA=="floor" && userDataB=="idol") {
levelFailed();
}
if (userDataA=="idol" && userDataB=="floor") {
levelFailed();
}
Could also have been written as follows:
if (userDataA=="floor" || userDataB=="floor") {
levelFailed();
}
This is because we already know the idol is one of the two bodies involved in
the collision.
 
Search WWH ::




Custom Search