You can apply setContactlistner to your world object, e.g.
world.setContactListener(new ContactListener() { @Override public void beginContact(Contact contact) { if(contact.getfixtureA.getBody().getUserData()=="body1"&& contact.getfixtureB.getBody().getUserData()=="body2") Colliding = true; System.out.println("Contact detected"); } @Override public void endContact(Contact contact) { Colliding = false; System.out.println("Contact removed"); } @Override public void postSolve(Contact arg0, ContactImpulse arg1) {
The beginContact() method will always call whenever any body overlaps or touches another body. You can also get body information from a contact object, for example contact.getFixtureA().getBody().getUserData(); if you want to do something with them. And when they separate from each other. EndContact() will call the method.
Hope this helps.
Jagdeep singh
source share