我正在尝试使用Libgdx,我有一个演员,只要我点击它就会执行一些操作。到目前为止它工作正常。现在我想为演员增添光芒。经过一些研究后,我遇到了Box2DLights。当我尝试将它添加到我的项目onClick Actor时工作正常似乎不起作用。我很确定这是由于rayhandler / Box2DLights,因为这是我正在做的唯一改变。这是我对Box2DLights进行的最小改动。
public class GameScreen implements Screen {
private RayHandler rayHandler;
private World world;
public GameScreen(Game game) {
this.game = game;
world = new World(new Vector2(0, 0), true);
rayHandler = new RayHandler(world);
rayHandler.setAmbientLight(0.1f, 0.1f, 0.1f, 1f);
rayHandler.setBlurNum(3);
}
@Override
public void show() {
viewport = new FitViewport(1080, 720);
stage = new Stage(viewport);
rayHandler.setCombinedMatrix(stage.getCamera().combined);
Gdx.input.setInputProcessor(stage);
}
@Override
public void render(float delta) {
//some custom rendering logic, but nothing related to rayHandler, excluding this for brevity.
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
stage.act(Gdx.graphics.getDeltaTime());
stage.draw();
rayHandler.updateAndRender();
}
现在当我调试时,我意识到onClick是
,这意味着某种方式筛选出的坐标(我知道很奇怪)。 你能帮忙吗?
答案 0 :(得分:2)
感谢@Mikhail Churbanov的回复here。 如果其他人再次发现这一点,那么这个解决方案是有效的。
box2lights doesn't auto-acquire custom viewports, and restores the 'default one' after the updateAndRender called - your need to set your custom 'fitted' viewport to rayHandler so that it would restore it correctly- using the rayHandler.useCustomViewport(...) method.
解释是test()
所有学分归@mikahi churbanov