在 LibGDx 中添加 rayhandler 会导致 InputListener 出现问题
Adding rayhandler in LibGDx causes issues in InputListener
我正在尝试 Libgdx,我有一个 actor,只要我们点击它就会执行一些动作。到目前为止它工作正常。现在我想给演员加光。在做了一些研究之后,我遇到了 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 是
比实际演员低一点
,这意味着以某种方式筛选了坐标(我知道这很奇怪)。
你能帮忙吗?
感谢@Mikhail Churbanov 的回复here。
如果其他人再次遇到这个问题,这里是有效的解决方案。
viewport = new FitViewport(1080, 720);
rayHandler.useCustomViewport(viewport.getScreenX(),
viewport.getScreenY(),
viewport.getScreenWidth(),
viewport.getScreenHeight());
解释是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.
所有学分@mikahi churbanov
我正在尝试 Libgdx,我有一个 actor,只要我们点击它就会执行一些动作。到目前为止它工作正常。现在我想给演员加光。在做了一些研究之后,我遇到了 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 是
比实际演员低一点
,这意味着以某种方式筛选了坐标(我知道这很奇怪)。 你能帮忙吗?
感谢@Mikhail Churbanov 的回复here。 如果其他人再次遇到这个问题,这里是有效的解决方案。
viewport = new FitViewport(1080, 720);
rayHandler.useCustomViewport(viewport.getScreenX(),
viewport.getScreenY(),
viewport.getScreenWidth(),
viewport.getScreenHeight());
解释是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.
所有学分@mikahi churbanov