I don't have any idea about the box2d collision detection in android. I googled and got results that suggest to use the contact listener but I don't know how to use it in android java.
2 Answers
\$\begingroup\$
\$\endgroup\$
If you're using JBox2D, you can use
org.jbox2d.dynamics.World.setContactListener(new ContactListener() {
...
});
\$\begingroup\$
\$\endgroup\$
2
OMG! that was the best help I've found! Thankyou Skyuzo. This code works for JBox2D (I haven't tried Android however, but Android would be using JBox2D instead of the C++ Box2D)
Inside the ContactListener, this code must be placed handling the contacts: Note This code should only be initialized once.
world.setContactListener(new ContactListener() {
@Override
public void beginContact(Contact contact) {
System.out.println("Contact detected");
}
@Override
public void endContact(Contact contact) {
System.out.println("Contact removed");
}
@Override
public void postSolve(Contact arg0, ContactImpulse arg1) {
// TODO Auto-generated method stub
}
@Override
public void preSolve(Contact arg0, Manifold arg1) {
// TODO Auto-generated method stub
}
});
-
\$\begingroup\$ Can't figure out if this is an answer or a thank you. \$\endgroup\$ Commented Feb 23, 2013 at 8:47
-
\$\begingroup\$ Looks like both. It's the same answer but it has the abstract methods implemented. \$\endgroup\$– HouseCommented Feb 23, 2013 at 17:22