我是 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);
}