首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Box2Dlights阴影不工作

Box2Dlights阴影不工作
EN

Stack Overflow用户
提问于 2014-06-22 14:22:28
回答 1查看 1.7K关注 0票数 1

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

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

下面是我的代码中使用Box2D和Box2Dlights的部分:

代码语言:javascript
复制
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);

及渲染部分:

代码语言:javascript
复制
// 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(),但是它们没有改变任何东西。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-06-24 17:17:43

阴影开始工作后,我设置软长度为零。

代码语言:javascript
复制
pointLight.setSoftnessLength(0);
coneLight.setSoftnessLength(0);
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/24352203

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档