# coloring box2d body in LibGDX

I want to color polygon of box2d in LibGDX. Found below useful class for that.

But, it is not coloring the body instead making colored shapes. I want colored bodies having all the property like gravity, restitution etc. In brief, I want to make colored ball and surface.And i don't want to attach sprite on bodies. Want just fill color in bodies.

Need some guidance????

You have to separate your physics simulation (bodies) from the graphical representation of the physics world.

Lets assume you have a Box2d body defined like this

float radius=3.0f;
CircleShape shape=new CircleShape();
FixtureDef fd = new FixtureDef();
fd.shape = shape;
BodyDef bd = new BodyDef();
bd.type = BodyType.DynamicBody;

Body body=world.createBody(bd);


Now in the render() method your first step the physics world

world.step(...)


Vector2 pos = body.getWorldCenter();