我刚刚在我的Box2DLights游戏中实现了LibGDX。它的工作,否则很好,但在我添加静态身体后,他们不会投阴影。

然而,墙确实以某种方式增加了点光。

下面是我的代码中使用Box2D和Box2Dlights的部分:
Vector2 gravity = new Vector2(0,0);
debugRenderer = new Box2DDebugRenderer();
world = new World(gravity, false);
rayHandler = new RayHandler(world);
rayHandler.setCombinedMatrix(camera.combined);
rayHandler.setShadows(true);
// This adds wall tiles from TiledMap into obstacles and to box2d world
for (MapObject wall : mapObjects) {
RectangleMapObject rmo = (RectangleMapObject) wall;
if (rmo.getName() == null || !rmo.getName().contentEquals("window")) {
Rectangle rec = rmo.getRectangle();
obstacles.add(rec);
rec.set(rec.x / 128 - mapRec.x, rec.y / 128 - mapRec.y,
rec.width / 128, rec.height / 128);
BodyDef bodyDef = new BodyDef();
bodyDef.type = BodyType.StaticBody;
bodyDef.position.set(rec.getX()+rec.width/2,rec.getY()+rec.height/2);
Body body = world.createBody(bodyDef);
PolygonShape groundBox = new PolygonShape();
groundBox.setAsBox(rec.width/2,rec.height/2);
body.createFixture(groundBox, 1.0f);
groundBox.dispose();
}
}
//The point light and the cone light;
pointLight= new PointLight(rayHandler, 100, new Color(1,1,1,0.5f), 0.5f, myCharacter.getAdjustedPosX(), myCharacter.getAdjustedPosY());
coneLight = new ConeLight(rayHandler, 100, new Color(1,1,1,0.5f), 3, myCharacter.getAdjustedPosX(), myCharacter.getAdjustedPosY(), myCharacter.getRotation(), 30f);及渲染部分:
// After I have rendered walls sprites etc.
world.step(1/60f, 6, 2);
rayHandler.setCombinedMatrix(camera.combined, camera.position.x, camera.position.y,camera.viewportWidth, camera.viewportHeight);
rayHandler.updateAndRender();
debugRenderer.render(this.world, camera.combined);我从许多教程和例子中尝试过一些东西,例如我添加了world.step(),但是它们没有改变任何东西。
发布于 2014-06-24 17:17:43
阴影开始工作后,我设置软长度为零。
pointLight.setSoftnessLength(0);
coneLight.setSoftnessLength(0);https://stackoverflow.com/questions/24352203
复制相似问题