我最近一直在试图回到LibGDX的Box2D版本,我回头看了几个月前创建的演示,并且我的代码看起来很好,并且从我的Google搜索结果,我的代码很好,但对于我的生活,我无法得到Fixture
呈现。LibGDX Box2D:无法获取灯具
这是我的(简约例子)的代码,并为我的生活,我不能得到它的工作注:我建围绕LibGDX Game
类的包装,应该是不言自明:
public class TestBox2D extends EGGame {
int width;
int height;
static final Vector2 ZERO_GRAVITY = new Vector2(0f, 0f);
OrthographicCamera camera;
World world;
Body body;
Box2DDebugRenderer box2dDebugRenderer;
RayHandler rayHandler;
... // Removed Constructor, nothing special here.
@Override
protected void init() {
width = Gdx.graphics.getWidth()/2;
height = Gdx.graphics.getHeight()/2;
camera = new OrthographicCamera(width, height);
camera.position.set(width/2, height/2, 0);
camera.update();
world = new World(ZERO_GRAVITY, true);
box2dDebugRenderer = new Box2DDebugRenderer();
rayHandler = new RayHandler(world);
rayHandler.setCombinedMatrix(camera.combined);
// creating Body
BodyDef bodyDef = new BodyDef();
bodyDef.type = BodyDef.BodyType.StaticBody;
bodyDef.position.set(width/2, height/2);
body = world.createBody(bodyDef);
CircleShape shape = new CircleShape();
shape.setRadius(1f);
FixtureDef fixtureDef = new FixtureDef();
fixtureDef.shape = shape;
body.createFixture(fixtureDef);
}
@Override
protected void updateGame() {
world.step(1f/30f, 6, 2);
rayHandler.update();
}
@Override
protected void renderGame() {
box2dDebugRenderer.render(world, camera.combined);
rayHandler.render();
}
@Override
public void dispose() {
world.dispose();
}
... // Removed main method, nothing special here.
}
请注意,world.getBodyCount();
和world.getFixtureCount();
均为return 1
。