我正在尝试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
略低于实际参与者的工作
,这意味着坐标不知何故被筛选了(我知道很奇怪)。你能帮帮忙吗?
发布于 2018-01-29 01:12:11
感谢@Mikhail Thanks的回复,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. All credits to @mikahi credits
https://stackoverflow.com/questions/48488569
复制相似问题