java - box2dlight libgdx point light not working -


so making 2d game using libgdx library. have been trying incorporate lighting system game using box2dlights library. however, reason point light wont appear on screen.

here code:

    private orthographiccamera camera; private spritebatch batch; private shaperenderer sr; private textureatlas textureatlas;      private rayhandler rayhandler;     private world world;      private tiledmap map; private orthogonaltiledmaprenderer renderer;  private float animationtime = 0; private player player; private int x = 400; private int currentdirection = 0; private int bulletdirection = 0; private boolean animationplaying = true; private boolean animationplaying2 = true; public animation walking; public animation walkingleft; public animation walkingright; public animation walkingup;  private collisionobjects co; private arraylist<playerpositions> allplayers = new arraylist<playerpositions>();  //modes arraylist<bulletworks> bullets = new arraylist<bulletworks>(); public boolean leftmode = false; public boolean frontmode = true; public boolean rightmode = false; public boolean upmode = false; public arraylist<positions> pos = new arraylist<positions>(); public float zoom = 0.1f; public float xposcamera = 0f; public float yposcamera = 0f; boolean keyprocessed = true; boolean play = false; private float currentposx = 400; private float currentposy = 400;  private pointlight pt;      public gamefirst(gametrial game) {         tmxmaploader loader = new tmxmaploader();         map = loader.load("data/whitewater.tmx");         batch = new spritebatch();         renderer = new orthogonaltiledmaprenderer(map);         sr = new shaperenderer();              camera = new orthographiccamera();             world = new world(new vector2(0, 0), true);              rayhandler = new rayhandler(world);             rayhandler.setculling(true);             rayhandler.usediffuselight(true);             rayhandler.setambientlight(0.2f, 0.2f, 0.2f,1.0f);            player = new player("prithvi2502", "currymonster69");         co = new collisionobjects();         allplayers.add(co.addpositionplayers(player));          pt = new pointlight(rayhandler, 50, color.cyan, 40, 400, 300);          camera.zoom = .5f;     }      @override     public void show() {      }       @override     public void render(float delta) {             gdx.gl.glclear(gl20.gl_color_buffer_bit);          // update         renderer.setview(camera);             rayhandler.update();          rayhandler.setcombinedmatrix(camera.combined.cpy().scl(100));          // render         renderer.render();          batch.begin();         inputupdate();         camera.update();         characterupdate();         batch.end();          rayhandler.render();     }      public void characterupdate() {             allplayers = co.updateplayerpositions(player.getplayerid(), player.getplayercurrentposx(), player.getplayercurrentposy(), allplayers);         currentposx =  player.getplayercurrentposx();     currentposy = player.getplayercurrentposy();         for(int i=0; < allplayers.size(); i++) {             system.out.println(allplayers.get(i).getplayerid() + " " + allplayers.get(i).getx() + " " + allplayers.get(i).gety());             currentposx = allplayers.get(i).getx();             currentposy = allplayers.get(i).gety();         }          (int = 0; < bullets.size(); i++) {             if(bullets.get(i).getdirection() == 0) {                     bullets.get(i).updatebuttom();                             if(bullets.get(i).didcollide(allplayers) == true) {                                     system.out.println("hit");                                     bullets.remove(i);                             } else if(bullets.get(i).gety() > 0 && bullets.get(i).gety() < 1080) {                                     bullets.get(i).draw(batch);                             }else {                                     bullets.remove(i);                             }             } else if(bullets.get(i).getdirection() == 1) {                     bullets.get(i).updateleft();                             if(bullets.get(i).didcollide(allplayers) == true) {                                     system.out.println("hit");                                     bullets.remove(i);                             } else if(bullets.get(i).getx() > 0 && bullets.get(i).getx() < 1920) {                                     bullets.get(i).draw(batch);                             } else {                                     bullets.remove(i);                             }             } else if(bullets.get(i).getdirection() == 2) {                     bullets.get(i).updateright();                             if(bullets.get(i).didcollide(allplayers) == true) {                                     system.out.println("hit");                                     bullets.remove(i);                             } else if(bullets.get(i).getx() > 0 && bullets.get(i).getx() < 1920) {                                     bullets.get(i).draw(batch);                             } else {                                     bullets.remove(i);                             }             } else if(bullets.get(i).getdirection() == 3) {                     bullets.get(i).updatetop();                             if(bullets.get(i).didcollide(allplayers) == true) {                                     system.out.println("hit");                                     bullets.remove(i);                             } else if(bullets.get(i).gety() > 0 && bullets.get(i).gety() < 1080) {                                     bullets.get(i).draw(batch);                             } else {                                     bullets.remove(i);                             }             }          }     }     public void inputupdate() {             if(gdx.input.iskeypressed(keys.a) ){            player.moveleft(camera, batch);            currentdirection = 2;         }else if(gdx.input.iskeypressed(keys.d) ){             player.moveright(camera, batch);             currentdirection = 1;         }else if(gdx.input.iskeypressed(keys.s) ){             player.movedown(camera, batch);             currentdirection = 0;         }else if(gdx.input.iskeypressed(keys.w) ){             player.moveup(camera, batch);             currentdirection = 3;         }else if(gdx.input.iskeypressed(keys.t) ){             bulletworks bw = new bulletworks((1920/2) + 300, 1080/2, (int) currentposx, (int) currentposy);             bulletdirection = 2;             bw.setdirection(bulletdirection);                 bullets.add(bw);          }else if(gdx.input.iskeypressed(keys.space)){             bulletworks bw = new bulletworks(1920/2, 1080/2, (int) currentposx, (int) currentposy);                  player.shoot(camera, batch);                 if(currentdirection == 0){                     bulletdirection = 0;              }else if(currentdirection == 1){                     bulletdirection = 1;              }else if(currentdirection == 2){                     bulletdirection = 2;              }else if(currentdirection == 3){                     bulletdirection = 3;              }                 bw.setdirection(bulletdirection);                 bullets.add(bw);         }else{              if(player.frontmode){                     setgametonormal(player.gettexture());              }else if(player.rightmode){                     setgametonormal(player.gettexture3());              }else if(player.leftmode){                     setgametonormal(player.gettexture2());              }else if(player.upmode){                     setgametonormal(player.gettexture4());              }                 play = false;         }     }     private void setgametonormal(textureregion texture) {             batch.draw(texture, 1920/2, 1080/2);     }      @override     public void resize(int width, int height) {             camera.settoortho(false, 1920, 1080);     }        @override     public void hide() {       }      @override     public void pause() {       }      @override     public void resume() {       }      @override     public void dispose() {             rayhandler.dispose();             world.dispose();             renderer.dispose();             map.dispose();             batch.dispose();             textureatlas.dispose();     } 

}

i think try render lights on default (black) background created every time libgdx refreshes screen. black background overweights , lights cannot rendered properly. black 'swallows' light.

i had same problem when first tried out box2d-lights. solved rendering colored background through 1x1 pixel texture on whole screen before calling rayhandler.render();

example code:

private spritebatch batch; private world world; private rayhandler rayhandler; private texture texture; private orthographiccamera camera;  @override public void show(){     batch = new spritebatch();     camera = new orthographiccamera();     camera.settoortho(false, 50, 50/16*9);     camera.position.set(0, 0, 0);     camera.update();     world = new world(new vector2(0, 0), true);     texture = new texture("white.png"); // 1x1 pixel texture     rayhandler = new rayhandler(world);     new pointlight(rayhandler, 32, color.cyan, 20, 0, 0); }  @override public void render(float delta){     gdx.gl.glclear(gl20.gl_color_buffer_bit);     world.step(delta, 8, 3);      batch.setprojectionmatrix(camera.combined);     batch.begin();     batch.draw(texture, -gdx.graphics.getwidth()/2, -gdx.graphics.getheight()/2, gdx.graphics.getwidth(), gdx.graphics.getheight());     batch.end();      rayhandler.setcombinedmatrix(camera.combined);     rayhandler.updateandrender(); } 

running code, following result

i not quite sure if best way it, worked me :)


Comments

Popular posts from this blog

shopping cart - Page redirect not working PHP -

php - How to modify a menu to show sub-menus -

python - Installing PyDev in eclipse is failed -