Java box2dlight libgdx点光源不工作

Java box2dlight libgdx点光源不工作,java,libgdx,box2dlights,Java,Libgdx,Box2dlights,所以我用libgdx库制作了一个2d游戏。最近,我一直在尝试使用Box2Lights库将照明系统整合到游戏中。但是,由于某些原因,点光源不会出现在屏幕上 这是我的密码: private OrthographicCamera camera; private SpriteBatch batch; private ShapeRenderer sr; private TextureAtlas textureAtlas; private RayHandler rayHandler;

所以我用libgdx库制作了一个2d游戏。最近,我一直在尝试使用Box2Lights库将照明系统整合到游戏中。但是,由于某些原因,点光源不会出现在屏幕上

这是我的密码:

    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; i < 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();
        }

        for (int i = 0; i < 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();
    }
私人正交摄影机;
专用SpriteBatch批次;
私人沙佩雷德勒高级;
私人织物;
私人RayHandler RayHandler;
私人世界;
私人平铺地图;
私有正交瓦片渲染器;
私有浮动动画时间=0;
私人玩家;
私有整数X=400;
私有int currentDirection=0;
私有方向=0;
私有布尔animationPlaying=true;
私有布尔动画播放2=true;
公共动画步行;
公共动画左行走;
公共动画步行权;
公共动画漫游;
私人碰撞物体公司;
private ArrayList allPlayers=new ArrayList();
//模式
ArrayList项目符号=新的ArrayList();
公共布尔leftMode=false;
公共布尔frontMode=true;
公共布尔rightMode=false;
公共布尔upMode=false;
public ArrayList pos=new ArrayList();
公共浮动缩放=0.1f;
公共浮点数xposCamera=0f;
公共浮动yposCamera=0f;
布尔键处理=真;
布尔播放=假;
专用浮点数currentPosx=400;
专用浮点电流Posy=400;
私人聚光灯;
公共游戏优先(GameTrial游戏){
TmxMapLoader loader=新的TmxMapLoader();
map=loader.load(“data/WhiteWater.tmx”);
批次=新的SpriteBatch();
渲染器=新的正交平铺贴图渲染器(贴图);
sr=新的ShaperEnder();
摄影机=新的正交摄影机();
世界=新世界(新矢量2(0,0),真);
rayHandler=新的rayHandler(世界);
rayHandler.setCulling(真);
rayHandler.useDiffuseLight(真);
设置环境光(0.2f、0.2f、0.2f、1.0f);
玩家=新玩家(“prithvi2502”、“currymonster69”);
CO=新的碰撞对象();
allPlayers.add(CO.addPositionPlayers(player));
pt=新的点光源(rayHandler,50,Color.CYAN,40,400,300);
照相机。变焦=.5f;
}
@凌驾
公开展览({
}
@凌驾
公共无效渲染(浮动增量){
Gdx.gl.glClear(GL20.gl\u颜色\u缓冲\u位);
//更新
渲染器.setView(摄像机);
raydhandler.update();
setCombinedMatrix(camera.combined.cpy().scl(100));
//渲染
render.render();
batch.begin();
inputUpdate();
camera.update();
characterUpdate();
batch.end();
render();
}
公共无效字符更新(){
allPlayers=CO.updatePlayerPositions(player.getPlayerID(),player.getPlayerCurrentPosX(),player.getPlayerCurrentPosY(),allPlayers);
currentPosx=player.getPlayerCurrentPosX();
currentPosy=player.getPlayerCurrentPosY();
对于(int i=0;i0&&shollets.get(i).getY()<1080){
子弹。获取(i)。抽取(批次);
}否则{
删除(i);
}
}else if(项目符号.get(i).getDirection()==1){
bullets.get(i.updateLeft();
如果(子弹。获取(i)。didclide(所有玩家)=真){
System.out.println(“命中”);
删除(i);
}else if(shollets.get(i).getX()>0&&shollets.get(i).getX()<1920){
子弹。获取(i)。抽取(批次);
}否则{
删除(i);
}
}else if(项目符号.get(i).getDirection()==2){
bullets.get(i.updateRight();
如果(子弹。获取(i)。didclide(所有玩家)=真){
System.out.println(“命中”);
删除(i);
}else if(shollets.get(i).getX()>0&&shollets.get(i).getX()<1920){
子弹。获取(i)。抽取(批次);
}否则{
删除(i);
}
}else if(项目符号.get(i).getDirection()==3){
bullets.get(i).updateTop();
如果(子弹。获取(i)。didclide(所有玩家)=真){
System.out.println(“命中”);
删除(i);
}else if(shollets.get(i).getY()>0&&shollets.get(i).getY()<1080){
子弹。获取(i)。抽取(批次);
}否则{
删除(i);
}
}
}
}
public void inputUpdate(){
如果(Gdx.input.isKeyPressed(按键A)){
player.moveLeft(相机、批次);
电流方向=2;
}else if(Gdx.input.isKeyPressed(Keys.D)){
player.mov
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();
}