【发布时间】:2014-06-25 01:17:43
【问题描述】:
我刚刚在我的 LibGDX 游戏中实现了 Box2DLights。它工作正常,但在我添加静态物体后,它们不会投射阴影。
然而,墙壁确实以某种方式增加了点光。
以下是我使用 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(),但它们并没有改变任何东西。
【问题讨论】: