Libgdx 无法查看Box2DebugRenderer';人体轮廓

Libgdx 无法查看Box2DebugRenderer';人体轮廓,libgdx,box2d,Libgdx,Box2d,从现在起,我暂时使用Box2DebugRenderer将实体渲染到世界中,但我无法看到运行时在世界中创建的实体的单色轮廓 这是我的游戏屏幕的代码: 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

从现在起,我暂时使用Box2DebugRenderer将实体渲染到世界中,但我无法看到运行时在世界中创建的实体的单色轮廓

这是我的游戏屏幕的代码:

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

BodyDef bodyDef=new BodyDef();
bodyDef.BodyType= BodyType.STATIC;
不同常数的值应适当,以便主体像您所做的那样位于摄影机视口中
常数。接地电阻X,
常数。地电位,
常数。地面宽度,
常数.地面高度

创建小车身并检查车身轮廓是否可见。
在这之后,如果你在屏幕上什么都没有,仍然可以使用SpriteBatch绘制简单的精灵

还有一个条件

可能您正在覆盖子游戏类中游戏的渲染方法,而没有调用父渲染方法。

需要在BodyDef中定义物理实体的BodyType

BodyDef bodyDef=new BodyDef();
bodyDef.BodyType= BodyType.STATIC;
不同常数的值应适当,以便主体像您所做的那样位于摄影机视口中
常数。接地电阻X,
常数。地电位,
常数。地面宽度,
常数.地面高度

创建小车身并检查车身轮廓是否可见。
在这之后,如果你在屏幕上什么都没有,仍然可以使用SpriteBatch绘制简单的精灵

还有一个条件
可能是您正在覆盖子游戏类中游戏的渲染方法,而不是调用父渲染方法