LibGDX Box2DLights 在渲染时抛出错误
LibGDX Box2DLights throws error on render
我试图让 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.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.run(LwjglApplication.java:120)
你试过用这个方法吗?
new PointLight(rayHandler, RAYS_NUM, new Color(1,1,1,1), lightDistance, x, y);
我也注意到了,你应该做的
world.step();
在 render() 方法的末尾。可能无法解决问题,但我刚刚注意到
我在新生成的 libgdx 项目中遇到了同样的问题,但是将 box2dlights 版本从 1.3 更新到 1.4 为我解决了这个错误。
我试图让 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.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.run(LwjglApplication.java:120)
你试过用这个方法吗?
new PointLight(rayHandler, RAYS_NUM, new Color(1,1,1,1), lightDistance, x, y);
我也注意到了,你应该做的
world.step();
在 render() 方法的末尾。可能无法解决问题,但我刚刚注意到
我在新生成的 libgdx 项目中遇到了同样的问题,但是将 box2dlights 版本从 1.3 更新到 1.4 为我解决了这个错误。