1

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);

                    }
            }
    });
techi.services
  • 8,473
  • 4
  • 39
  • 42
user1391058
  • 265
  • 4
  • 19

2 Answers2

4

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.

Plastic Sturgeon
  • 12,527
  • 4
  • 33
  • 47
0

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

Kalpesh
  • 1,767
  • 19
  • 29