为什么身体不会在重力作用下坠落?

时间:2013-10-14 16:18:30

标签: box2d libgdx jbox2d

我是box2d和libgdx游戏开发框架的新手。

我创造了一个世界和一个圆形。

我遇到重力问题。我在libgdx box2d中创建的Circle并没有受到重力的影响。请帮我解决这个问题。

public void render(float delta) {
    Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT); 

    box2dDebugRenderer.render(world, orthographicCamera.projection);

    world.step(TIME_STEMP, VELOCITY_ITERAIONS, POSITION_ITERATION);
    System.out.println(b.getPosition().y);
}

@Override
public void resize(int width, int height) {
    orthographicCamera.setToOrtho(false, width/10, height/10);
    orthographicCamera.update();
}

@Override
public void show() {
    world = new World(new Vector2(0, -9.81f), true);
    box2dDebugRenderer = new Box2DDebugRenderer();
    orthographicCamera = new OrthographicCamera();


    BodyDef balldef = new BodyDef();
    balldef.type = BodyType.DynamicBody;
    balldef.position.set(0, 1);



    CircleShape ballshape = new CircleShape();
    ballshape.setRadius(1f);


    FixtureDef ballfixture = new FixtureDef();
    ballfixture.density = 1000f;
    ballfixture.friction = .3f;
    ballfixture.restitution = .7f;
    ballfixture.shape = ballshape;

    b = world.createBody(balldef);
    f = b.createFixture(ballfixture);


} 

1 个答案:

答案 0 :(得分:6)

这是你的问题.-

final float TIME_STEMP = 1/60;

你正在进行整数除法,得到0。换句话说,你的世界陷入了困境。试试这个.-

final float TIME_STEMP = 1.0f / 60.0f;