I made complex dynamic body that rotates around other body that is static. It works perfectly, however I got messed up with sprite position on that body.
Here's what I have now
and here's what I need to have
I will add my code
private Body createSide(float x, float y, Sprite tmpSprite, boolean sharp){
BodyDef bDef = new BodyDef();
bDef.type = BodyDef.BodyType.DynamicBody;
PolygonShape shape = new PolygonShape();
if(!sharp){
shape.setAsBox(1.8f / PPM, 0.2f / PPM);
} else {
shape.setAsBox(0.2f / PPM, 1.8f / PPM);
}
FixtureDef fdef = new FixtureDef();
fdef.shape = shape;
bDef.position.set(x, y);
Body body = world.createBody(bDef).createFixture(fdef).getBody();
body.setAngularVelocity(-1f);
tmpSprite.setPosition(bDef.position.x * 32, bDef.position.y * 32);
return body;
}
private void createBody(int y, final int V_WIDTH){
staticBody = createStaticBody(y, V_WIDTH);
Body rightSide = createSide(5.5f, 15, sprites[0], true);
Body leftSide = createSide(9.5f, 15, sprites[1], true);
Body top = createSide(7.5f, 17, sprites[2], false);
Body bottom = createSide(7.5f, 13, sprites[3], false);
bodies[0] = rightSide;
bodies[1] = leftSide;
bodies[2] = top;
bodies[3] = bottom;
...
...
...
}
and here's my draw method
@Override
public void draw(SpriteBatch sb) {
for (int i=0; i<bodies.length; i++){
sprites[i].setRotation(bodies[i].getAngle() * MathUtils.radiansToDegrees);
sprites[i].draw(sb);
}
}