2

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

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

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

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);


} 
4

1 回答 1

6

这是你的问题。-

final float TIME_STEMP = 1/60;

你正在做一个整数除法,结果是0. 换句话说,你的世界被时间卡住了。试试这个。-

final float TIME_STEMP = 1.0f / 60.0f;
于 2013-10-14T16:32:07.983 回答