Game Development Reference
In-Depth Information
---------------------------
a collision has been post solved
first body: Floor
second body: Ball
impulse: 57.07226654021458
---------------------------
a collision ended
first body: Floor
second body: Ball
---------------------------
6.
At every bounce, all four functions are called, with a decreasing impulse as
the ball bounces lower and lower.
And that's how contact listeners work, the sequence never changes, and
following are its steps, from first to last:
i. Begin Contact Event is called when the collision has been detected.
ii. Pre-Solve Event is called before the collision is processed.
iii. Post-Solve Event is called after the collision has been processed.
iv. End Contact Event is called when there's no more collision, which
may not occur if the bodies keep colliding, such as the ball on the
floor when it does not bounce anymore.
With these concepts in mind, let's do something interesting with our Totem
Destroyer prototype.
Detecting when the idol falls on the floor
in Totem Destroyer
We want the player to fail the level if the idol hits the ground, that is the static body
at the bottom. Let's perform the following steps to achieve this:
1.
Take the last Totem Destroyer we made in Chapter 3 , Interacting with Bodies ,
the one with the text field monitoring idol attributes, and assign a custom
data to the floor body changing the floor function in the following way:
private function floor():void {
var bodyDef:b2BodyDef=new b2BodyDef();
bodyDef.position.Set(320/worldScale,465/worldScale);
 
Search WWH ::




Custom Search