0
votes

Should I only ever have one box2d contact listener in a project?

Let's say I have a bird and a rock. Would they use the same listener or have their own?

Thanks

2

2 Answers

0
votes

Use one contact listener, and have it handle what happens with various combinations of objects collide.

Normally i just tell each object it collided with the other, and let it decide internally if it should do anything beyond that.

0
votes

You only need one contact listener.

Note the listener is 'initialized'. It runs once. It isn't meant for multiple instances. It would consume memory and cause slowdown.

Keep all your items in an array or vector object.

Manage the conditionals with an contact listener class. Iterate through the object to test if things hit each other.