我是 Box2D 和 LibGDX 的新手,我正在尝试进行一个简单的测试。该代码应该呈现一个 2x2 框,但它没有这是我的代码:
public class PhysicsDemo implements ApplicationListener {
World world = new World(new Vector2(0, -20), true);
Box2DDebugRenderer debugRenderer;
private OrthographicCamera camera;
@Override
public void create() {
camera = new OrthographicCamera();
camera.position.set(0, 0, 0);
//Ground body
BodyDef groundBodyDef =new BodyDef();
groundBodyDef.position.set(0.0f, -20f);
Body groundBody = world.createBody(groundBodyDef);
PolygonShape groundBox = new PolygonShape();
groundBox.setAsBox(50.0f, 10.0f);
groundBody.createFixture(groundBox, 0.0f);
//Dynamic Body
BodyDef bodyDef = new BodyDef();
bodyDef.type = BodyType.DynamicBody;
bodyDef.position.set(0.0f, 4.0f);
Body body = world.createBody(bodyDef);
PolygonShape dynamicBox = new PolygonShape();
dynamicBox.setAsBox(1.0f, 1.0f);
FixtureDef fixtureDef = new FixtureDef();
fixtureDef.shape = dynamicBox;
fixtureDef.density = 1.0f;
fixtureDef.friction = 0.3f;
body.createFixture(fixtureDef);
debugRenderer = new Box2DDebugRenderer();
}
@Override
public void dispose() {
}
@Override
public void render() {
Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
debugRenderer.render(world, camera.combined);
}
@Override
public void resize(int width, int height) {
}
@Override
public void pause() {
}
@Override
public void resume() {
}
}
我似乎无法显示任何东西,我得到的只是黑屏。有谁知道出了什么问题?
谢谢!