Reputation: 265
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
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
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