I am new using the library and incorporating box2d, I have run into a problem and that is that I have created 2 protagonists of which both are dynamic and I would like to know if there is any way or any function to indicate that they can collide with each other and I don't know cross over
CodePudding user response:
You can use a ContactListener, to let the Box2D world inform you, about every contact of objects. Therefore your protagonist's classes need to implement the ContactListener interface and be registered in the Box2D world (using the setContactListener method).
Now if any contact happens, the beginContact method of your protagonist's class will be called.
But this will happen for every contact. Not only the contacts between your protagonists, so you'll have to filter. This is usually done, by checking the Fixtures of a Contact (that is passed to your beginContact method). Using the Fixtures you can get the colliding Body and its user data, which you can set to the protagonist to identify him.
For further information have a look at this tutorial or the libGDX documentation on Box2D
