You already did it the right way to create and set a ContactListener... (for a general setup, the libgdx wiki is great: https://github.com/libgdx/libgdx/wiki/box2d#contact-listeners)
If you now want to handle the specific contacts, you for exmaple need to add some implementation in the beginContact();
method of your listener. The beginContact();
method contains a Contact
instance, which holds all you need:
- FixtureA - the first fixture of a contact
- FixtureB - the fixture, which FixtureA has collided with
- WorldManifold - an object that holds the collision points etc
Through the fixtures you can access the bodies and the actors which you are drawing. The connection to your Actor can be done through the body.setUserData(actor);
method.
Now you need to decide on how to find out the correct collisions. You can either work with sensors, which are box2d fixtures that just act as a sensor. That means that when an object collides with a sensor, it won't bounce, but fall through it instead. But you then are able to detect this contact within the listener.
Also, it might be a good idea to add some kind of GameObjectType to your actors. Imagine you create a jumping game where the player jumps from platform to platform with water below. Then you would create your actors with types like PLAYER, WATER, PLATFORM ... through the getUserData() method of the box2d bodies yu can now access the Actors and compare their types.
E.g. when an Actor of type PLAYER collides with one of type WATER, he will drown...
Hope it helps...