Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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.

share|improve this question
add comment

2 Answers 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
        }
    });
share|improve this answer
    
Can't figure out if this is an answer or a thank you. –  Cameron Fredman Feb 23 '13 at 8:47
    
Looks like both. It's the same answer but it has the abstract methods implemented. –  Byte56 Feb 23 '13 at 17:22
add comment

If you're using JBox2D, you can use

org.jbox2d.dynamics.World.setContactListener(new ContactListener() {
    ...
});
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.