1
我現在暫時使用box2ddebugrenderer將身體呈現到世界中,但我無法看到運行時在世界中創建的物體的單色輪廓。無法看到Box2DdebugRenderer的身體輪廓
這是我的遊戲屏幕的代碼:
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;
}
}