how toget x and y cooridinates of sprit2 when sprite1 collides with it in AndEngine

how to get x and y coordinates of sprit2 when sprite1 collides with it i use collision update handler. my requirement is when sprite 1 collide with sprite2 it attach with sprite2 on that point where it collides? Thanks.

Upvotes: 0

Views: 191

Answers (1)

a_schimpf
a_schimpf

Reputation: 765

try using the Box2D extension for andengine. you basically attach physics bodies to sprites. then you use a contact listener to take care of collision events. here is how you would get the contact points of the collision in the listener...

protected ContactListener createContactListener() {
    return new ContactListener() {
        public void beginContact(Contact contact) {
            Vector2[] contactPoints = contact.getWorldManifold().getPoints();
             for(int i = 0; i < contactPoints.length; i++) {
                 ...
             }
             ...
        }
    }
}

Upvotes: 1

Related Questions