我想试用Box2d,并在教程中编写类似的代码,所有内容都正确呈现,但没有更新,也没有例外。请帮助我,我想我会疯了。
@Override
public void create () {
world = new World(new Vector2(0, -10f), true);
r = new Box2DDebugRenderer();
camera = new OrthographicCamera(100, 100);
camera.translate(50, 50, 0);
BodyDef bd = new BodyDef();
bd.type = BodyType.DynamicBody;
bd.position.set(50, 50);
Body body = world.createBody(bd);
CircleShape cs = new CircleShape();
cs.setRadius(1);
FixtureDef fd = new FixtureDef();
fd.shape = cs;
body.createFixture(fd);
cs.dispose();
BodyDef b = new BodyDef();
b.type = BodyType.StaticBody;
b.position.set(30, 30);
Body bo = world.createBody(b);
PolygonShape ps = new PolygonShape();
ps.setAsBox(10, 3);
FixtureDef f = new FixtureDef();
f.shape = ps;
bo.createFixture(f);
ps.dispose();
}
@Override
public void render () {
Gdx.gl.glClearColor(1, 0, 0, 1);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
r.render(world, camera.combined);
camera.update();
world.step(1/60, 6, 2);
}
答案 0 :(得分:3)
当然box2D仍然适用于Libgdx
你的问题就在这一行
world.step(1/60, 6, 2);
尝试这样做
world.step(1/60f, 6, 2);
你的时间步长是考虑因素0因为1/60整数是0
我测试了你的代码它会起作用!
祝你好运