Howdy!
Im about to finish my first box2d game but i have a serious problem though. Im trying to add some sound when 2 bodies hit eachother.
The problem is that im using my contact listener and override the functions there. The problem is that the contact listener is based on points so whenever 2 points from 2 bodies are hiting eachother the sound play so if more points form those 2 bodies hit the sound will play over and over and im not sure what to do.
I just want the sound to play once when the bodies collide even if more points from those 2 objects get contact.
Here's my contact listener code:
Code:
override public function Add(point:b2ContactPoint):void
{
if(point.shape1.IsSensor() || point.shape2.IsSensor())
{
soundChannel1.stop();
}
if(point.shape1.GetBody().GetMass()==0 || point.shape2.GetBody().GetMass()==0)
{
soundChannel1=soundContact1.play();
soundChannel1.soundTransform=Volume5;
}
if(point.shape1.GetBody().GetMass()>0 && point.shape2.GetBody().GetMass()>0)
{
soundChannel1=soundContact3.play();
soundChannel1.soundTransform=Volume5;
}
}
override public function Persist(point:b2ContactPoint):void
{
soundChannel1.stop();
}
override public function Remove(point:b2ContactPoint):void
{
soundChannel1.stop();
super.Remove(point);
}
override public function Result(point:b2ContactResult):void
{
}
Trying to stop the sound if the contact "Persists" but not geting much effect!
So any suggestion how i should do this? I would appreciate.