【发布时间】:2013-07-07 14:57:15
【问题描述】:
我是 Box2D 的新手。我只是想遵循一个简单的教程,但试图将它集成到我的代码中:
我开始创建我的 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();
}
最后,Timer 会定期创建新对象。在这些对象的构造函数中,我创建了 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();:) -
是的,我知道!但我要解决的问题与绘制舞台无关:D!
-
javaw.exe是否出现错误?