user1391058
user1391058

Reputation: 265

Collision detection In Andengine

I wanna get collision detection between AnimatedSprite which is Body of box2d and Shape.I'm using codes below.But it gives error. "walls" is a rectangle shape, "player" is animatedsprite.

scene.registerUpdateHandler(new IUpdateHandler() {
            public void reset() { }

            public void onUpdate(final float pSecondsElapsed) {
                    if(walls.collidesWith(player)) {
                        walls.setColor(1, 0, 0);
                    } else {
                        walls.setColor(0, 1, 0);
                    }



                    if(!mCamera.isRectangularShapeVisible(player)) {
                        walls.setColor(1, 0, 1);

                    }
            }
    });

Upvotes: 1

Views: 1661

Answers (2)

Kalpesh
Kalpesh

Reputation: 1807

In AndEngine box2d, you can detect collision by ContractListener. You can check useful details for how to use ContactListener in AndEngine box2d. click here

Upvotes: 0

Plastic Sturgeon
Plastic Sturgeon

Reputation: 12527

The collidesWith function is not part of the box2D collision detection. You need to use a Box2D ContactListener to listen to collisions in the engine and handle them there.

Upvotes: 4

Related Questions