无法看到 Box2DdebugRenderer 的 body 轮廓

Unable to see Box2DdebugRenderer's body outlines

我暂时使用 box2ddebugrenderer 将身体渲染到世界中,但我无法看到 mono-color 在 运行 时在世界中创建的身体轮廓。

这是我游戏画面的代码:

public class GameScreen implements Screen {

static final int VIEWPORT_WIDTH = 20;
static final int VIEWPORT_HEIGHT = 13;

World world;
Body ground;

final float TIME_STEP = 1 / 300f;
float accumulator = 0f;

OrthographicCamera camera;
private Box2DDebugRenderer renderer;

@Override
public void render(float delta) {
    //Clear the screen
    Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);

    renderer.render(world, camera.combined);

    accumulator += delta;

    while (accumulator >= delta) {
        world.step(TIME_STEP, 6, 2);
        accumulator -= TIME_STEP;
    }
}



@Override
public void show() {
    world = createWorld();
    ground = createGround(world);
    renderer = new Box2DDebugRenderer();

    camera = new OrthographicCamera(VIEWPORT_WIDTH, VIEWPORT_HEIGHT);
    camera.position.set(camera.viewportWidth / 2, camera.viewportHeight / 2, 0f);
    camera.update();

}

public World createWorld() {
    return new World(Constants.WORLD_GRAVITY, true);
}

public Body createGround(World world) {
    BodyDef bodyDef = new BodyDef();
    bodyDef.position.set(new Vector2(Constants.GROUND_X, Constants.GROUND_Y));
    Body body = world.createBody(bodyDef);
    PolygonShape shape = new PolygonShape();
    shape.setAsBox(Constants.GROUND_WIDTH / 2, Constants.GROUND_HEIGHT / 2);
    body.createFixture(shape, Constants.GROUND_DENSITY);
    shape.dispose();
    return body;
}
}    

需要在 BodyDef

中定义物理的 BodyType body
BodyDef bodyDef=new BodyDef();
bodyDef.BodyType= BodyType.STATIC;

不同常量的值应该是合适的,这样 body 就像你
一样位于相机视口内 Constants.GROUND_X,
Constants.GROUND_Y,
Constants.GROUND_WIDTH,
Constants.GROUND_HEIGHT

创建小 body 并检查,body 轮廓是否可见。
在此之后,如果屏幕上没有任何内容,请使用 SpriteBatch 绘制简单的 Sprite。

还有一个条件
可能是您在 Child 游戏 class 中覆盖了游戏的渲染方法,而不是调用 parent 渲染方法。