I'm trying to detect a collision between an AnimatedSprite and the Rectangle floor. When they collide, I want the sprite to be removed. However, I keep getting a null pointer error. Am I doing this the wrong way?
Inside my add face function. face is an AnimatedSprite created, and ground is a rectangle.
this.mScene.registerUpdateHandler(new IUpdateHandler() {
@Override
public void reset() { }
@Override
public void onUpdate(final float pSecondsElapsed) {
if(face.collidesWith(ground)) {
Debug.d("Contact!");
removeFace(face);
}
}
});
removeFace() is:
private void removeFace(final AnimatedSprite face) {
final PhysicsConnector facePhysicsConnector = this.mPhysicsWorld.getPhysicsConnectorManager().findPhysicsConnectorByShape(face);
this.mPhysicsWorld.unregisterPhysicsConnector(facePhysicsConnector);
this.mPhysicsWorld.destroyBody(facePhysicsConnector.getBody());
this.mScene.unregisterTouchArea(face);
this.mScene.detachChild(face);
System.gc();
}
The null pointer exception is inside removeFace()
