I have a ball strike a player and an explosion is animated.
At high velocities, I need the animation to be triggered before the actual impact.
I created a larger sensor, but there is a gray area, because I don't want to trigger the animation if the player moves out of the way in time.
In other words, when in the earliest I can trigger an event based on a collision.
Presently, the animation is triggered in begincontact() by a conditional statement.
At high velocities, I need the animation to be triggered before the actual impact.
I created a larger sensor, but there is a gray area, because I don't want to trigger the animation if the player moves out of the way in time.
In other words, when in the earliest I can trigger an event based on a collision.
Presently, the animation is triggered in begincontact() by a conditional statement.
Code: Select all
public class BallContactListener extends b2ContactListener
{
override public function BeginContact(contact:b2Contact):void
{
// set ball1:vector equal to UserData about collision
var ball1:Ball = contact.GetFixtureA().GetBody().GetUserData();
var ball2:Ball = contact.GetFixtureB().GetBody().GetUserData();
var manifold:b2WorldManifold = new b2WorldManifold();
contact.GetWorldManifold(manifold);
var points:Vector.<b2Vec2> = manifold.m_points;
var contactA = contact.GetFixtureA().GetBody().GetUserData().texture;
var contactB = contact.GetFixtureB().GetBody().GetUserData().texture;
if (contactA != null && contactB != null)
{
// if a ball hits the player or player hits the ball
if((contact.GetFixtureB().GetBody().GetUserData().texture is BallImage && contact.GetFixtureA().GetBody().GetUserData().texture is PlayerImage)
||
(contact.GetFixtureA().GetBody().GetUserData().texture is BallImage && contact.GetFixtureB().GetBody().GetUserData().texture is PlayerImage))
{
// load the blue animation
ball1.addEffect(points[0],SmallBubbleAnimation);
ball2.addEffect(points[0],SmallBubbleAnimation);
if(contact.GetFixtureB().GetBody().GetUserData().texture is PlayerImage)
{
//run the chomp animation
ball2.addAnimation(PlayerSwallow);
}
if(contact.GetFixtureA().GetBody().GetUserData().texture is PlayerImage)
{
//run the chomp animation
ball1.addAnimation(PlayerSwallow);
}
//Player got the ball
if(contact.GetFixtureB().GetBody().GetUserData().texture is BallImage)
{
Destructor.playerScore ++;
Destructor.scoreChanged = true;
Destructor.DestroyList.push(ball2);
}
if(contact.GetFixtureA().GetBody().GetUserData().texture is BallImage)
{
Destructor.playerScore ++;
Destructor.scoreChanged = true
Destructor.DestroyList.push(ball1);
}
}
// if a box hits the player or player hits the box
if((contact.GetFixtureB().GetBody().GetUserData().texture is BoxImage && contact.GetFixtureA().GetBody().GetUserData().texture is PlayerImage)
||
(contact.GetFixtureA().GetBody().GetUserData().texture is BoxImage && contact.GetFixtureB().GetBody().GetUserData().texture is PlayerImage))
{
// load the damage animation
ball1.addEffect(points[0], RedBubbleAnimation);
ball2.addEffect(points[0], RedBubbleAnimation);
// load the player animation
if(contact.GetFixtureB().GetBody().GetUserData().texture is BoxImage)
{
//fade out the ball after contact
Fader.FadeList.push(ball2);
}
if(contact.GetFixtureA().GetBody().GetUserData().texture is BoxImage)
{
Fader.FadeList.push(ball1);
}
} // end contact type check
} // end contact check
} // end begin contact override
} // end listener class