LibGDX Box2DLights在渲染时抛出错误

时间:2015-07-02 17:16:37

标签: java libgdx box2d box2dlights

我想让一个Box2D PointLight在屏幕上渲染,但在渲染时会抛出异常。我修改了API和Box2D用户手册,并观看了有关该主题的视频,但还没有找到解决我问题的方法。这是我的代码和错误。

package com.mygdx.test;

import box2dLight.PointLight;
import box2dLight.RayHandler;

import com.badlogic.gdx.ApplicationAdapter;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.physics.box2d.World;

public class Test extends ApplicationAdapter {
    /** the camera **/
    OrthographicCamera camera;
    RayHandler rayHandler;
    World world;

    @Override
    public void create() {
        camera = new OrthographicCamera(48, 32);
        camera.update();
        world = new World(new Vector2(0, -10), true);
        rayHandler = new RayHandler(world);
        new PointLight(rayHandler, 32);
    }

    @Override
    public void render() {
        Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
        world.step(Gdx.graphics.getDeltaTime(), 8, 3);
        rayHandler.setCombinedMatrix(camera.combined);
        rayHandler.updateAndRender();
    }

错误:

Exception in thread "LWJGL Application" com.badlogic.gdx.utils.GdxRuntimeException: java.lang.NoSuchMethodError: com.badlogic.gdx.graphics.glutils.FrameBuffer.getColorBufferTexture()Lcom/badlogic/gdx/graphics/Texture;
at com.badlogic.gdx.backends.lwjgl.LwjglApplication$1.run(LwjglApplication.java:127)
Caused by: java.lang.NoSuchMethodError: com.badlogic.gdx.graphics.glutils.FrameBuffer.getColorBufferTexture()Lcom/badlogic/gdx/graphics/Texture;
at box2dLight.LightMap.gaussianBlur(LightMap.java:76)
at box2dLight.LightMap.render(LightMap.java:37)
at box2dLight.RayHandler.render(RayHandler.java:328)
at box2dLight.RayHandler.updateAndRender(RayHandler.java:262)
at com.mygdx.test.Test.render(Test.java:33)
at com.badlogic.gdx.backends.lwjgl.LwjglApplication.mainLoop(LwjglApplication.java:215)
at com.badlogic.gdx.backends.lwjgl.LwjglApplication$1.run(LwjglApplication.java:120)

2 个答案:

答案 0 :(得分:2)

我对新生成的libgdx项目有同样的问题,但是将box2dlights版本从1.3更新到1.4可以解决这个错误。

答案 1 :(得分:0)

您是否尝试过使用此方法?

new PointLight(rayHandler, RAYS_NUM, new Color(1,1,1,1), lightDistance, x, y);

我也注意到了,你应该做

world.step();

render()方法的末尾。可能不会解决问题,但我只是注意到了