Search code examples
jbox2d

Can't Create Static Object in Box2D


Well, more specifically, JBox2D. I have a circle falling down, and when clicked on, the circle becomes a box and becomes static (Doesn't move, regardless of gravity or collisions). My understanding is that to make it static, I set the density to 0. This isn't working though, and for some reason nothing is colliding with the object either. Below is where I turn the circle into a static box.

physBall.destroyFixture(fixture);

PolygonShape b = new PolygonShape();
b.setAsBox(radius*2.2f, radius);

FixtureDef fd = new FixtureDef();
fd.shape = b;
fd.friction = 0;
fd.density = 0;
physBall.createFixture(fd);

I feel that this is an easy fix, but the solution simply evades me.


Solution

  • i only used Box2D on the iPhone, but i think you just need to call

    body.setType(BodyType.STATIC)
    

    on your Body instance.