我是Box2D的新手。我只是想跟随一个简单的教程,而是试图将其整合我的代码里面:Box2D Libgdx黑色屏幕
我开始创建我的Libgdx游戏:
public void create() {
float w = Gdx.graphics.getWidth();
float h = Gdx.graphics.getHeight();
camera = new OrthographicCamera(w, h, 0);
camera.position.set(camera.viewportWidth * .5f, camera.viewportHeight * .5f, 0f);
camera.update();
batch = new SpriteBatch();
viewSwitcher("GameScreen",null);
}
到viewSwitcher的调用,创建一个新的对象,它创建了一个新画面:
public GameScreenController(SomeGame t, String id) {
somegame = t;
db = t.getDB();
world = new World(new Vector2(0, -20), true);
screen = new GameScreen(this);
[. . .]
}
里面的游戏屏幕(它扩展了Screen类)我有渲染方法:
@Override
public void render(float delta) {
debugRenderer.render(world, camera.combined);
world.step(BOX_STEP, BOX_VELOCITY_ITERATIONS, BOX_POSITION_ITERATIONS);
stage.act(delta);
//stage.draw();
}
最后,一个定时器,定期创建新的对象。这些对象的构造函数中,我有bodyDef的创建:
public void createBodyLetter() {
BodyDef bodyDef = new BodyDef();
bodyDef.type = BodyType.DynamicBody;
bodyDef.position.set(200, 200);
Body body = controller.getWorld().createBody(bodyDef);
PolygonShape dynamicBox = new PolygonShape();
dynamicBox.setAsBox(1.0f, 1.0f);
FixtureDef fixtureDef = new FixtureDef();
fixtureDef.shape = dynamicBox;
fixtureDef.density = 1.0f;
fixtureDef.friction = 0.3f;
body.createFixture(fixtureDef);
dynamicBox.dispose();
}
结果当我开始这个计划只是一个黑色的屏幕。有谁知道问题在哪里?
谢谢
也许,取消注释'//stage.draw();':) – Pavel
是的,我知道!但我想解决的问题与绘制舞台无关:D! –
javaw.exe出现错误吗? –