作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我是 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);
}
最佳答案
这是你的问题。-
final float TIME_STEMP = 1/60;
您正在进行整数除法,结果为 0
。换句话说,你的世界被困在了时间里。试试这个。-
final float TIME_STEMP = 1.0f / 60.0f;
关于box2d - 为什么 body 不会在重力作用下下落?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19364637/
我是一名优秀的程序员,十分优秀!