[box2d 2.02] Contact Listener Sound

Discuss issues specific to the Flash/AS3 port of Box2D
kestorr
Posts: 32
Joined: Tue May 22, 2012 2:37 am

[box2d 2.02] Contact Listener Sound

Postby kestorr » Sat Aug 25, 2012 2:08 pm

Hello there.
I have encountered a problem while trying to add sound on my game through override the functions inside contactlistener class.
The problem is this.
At some point there are many objects around (bodies) and when the sounds are playing, the game sudently stops (i guess because theres at some points too many sounds playing at the same time).
And i Get the following errors:

TypeError: Error #1009: Cannot access a property or method of a null object reference.
at GameContactListener/Add()
at Box2D.Dynamics.Contacts::b2PolygonContact/Evaluate()
at Box2D.Dynamics.Contacts::b2Contact/Update()
at Box2D.Dynamics::b2ContactManager/Collide()
at Box2D.Dynamics::b2World/Step()
at Main/eFrame()


TypeError: Error #1009: Cannot access a property or method of a null object reference.
at GameContactListener/Persist()
at Box2D.Dynamics.Contacts::b2PolygonContact/Evaluate()
at Box2D.Dynamics.Contacts::b2Contact/Update()
at Box2D.Dynamics::b2ContactManager/Collide()
at Box2D.Dynamics::b2World/Step()
at Main/eFrame()

Any idea how can i get rid of these errors?

kestorr
Posts: 32
Joined: Tue May 22, 2012 2:37 am

Re: [box2d 2.02] Contact Listener Sound

Postby kestorr » Sat Aug 25, 2012 2:17 pm

This is the code im using inside the Add function

Code: Select all


if(point.shape1.GetBody().GetUserData() is BallActor || point.shape2.GetBody().GetUserData() is BallActor)
{
   if(point.shape1.GetBody().GetLinearVelocity().x>20 || point.shape1.GetBody().GetLinearVelocity().x<-20 ||
     point.shape2.GetBody().GetLinearVelocity().x>20 || point.shape2.GetBody().GetLinearVelocity().x<-20 ||
      point.shape1.GetBody().GetLinearVelocity().y>20 || point.shape1.GetBody().GetLinearVelocity().y<-20 ||
      point.shape2.GetBody().GetLinearVelocity().y>20 || point.shape2.GetBody().GetLinearVelocity().y<-20)
   {
      if(point.shape1.GetBody().GetUserData() != null || point.shape2.GetBody().GetUserData() != null)
      {
         soundChannel=soundHit.play();
         soundChannel.soundTransform=Volume7;
      }
   }
}


kestorr
Posts: 32
Joined: Tue May 22, 2012 2:37 am

Re: [box2d 2.02] Contact Listener Sound

Postby kestorr » Sat Aug 25, 2012 8:39 pm

I have solved the problem by raising a flag and handling the sound in my main class.


Return to “Flash”



Who is online

Users browsing this forum: No registered users and 1 guest