I have two bodies(A,B). I want B follows A. I can change B position with setTransfrom() function to A position. But I have to change B's position in every frame rate. So I have to use something like contact listener. When I use normal object in Andengine, it has this function below instead of contactlistener.
this.foot = new Rectangle(this.getX(), this.getY(), 8, 10, ResourcesManager.getInstance().vbom){
@Override
protected void onManagedUpdate(float pSecondsElapsed)
{
// super.onManagedUpdate(pSecondsElapsed);
this.setPosition(body.getPosition().x*PhysicsConstants.PIXEL_TO_METER_RATIO_DEFAULT+1,
body.getPosition().y*PhysicsConstants.PIXEL_TO_METER_RATIO_DEFAULT-15);
}
};
I mean I can set this kind of listener when I am creating it.Is there any option for box2d body? I mean something like that:
this.footBody=PhysicsFactory.createBoxBody(this.mPhysicsWorld, this.foot, BodyType.DynamicBody, footFixtureDef){
@Override
protected void onManagedUpdate(float pSecondsElapsed)
{
// super.onManagedUpdate(pSecondsElapsed);
this.setPosition(body.getPosition().x*PhysicsConstants.PIXEL_TO_METER_RATIO_DEFAULT+1,
body.getPosition().y*PhysicsConstants.PIXEL_TO_METER_RATIO_DEFAULT-15);
}
};