首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在LibGDx中添加光线处理程序导致InputListener出现问题

在LibGDx中添加光线处理程序导致InputListener出现问题
EN

Stack Overflow用户
提问于 2018-01-29 00:28:21
回答 1查看 143关注 0票数 2

我正在尝试Libgdx,我有一个参与者,只要我们点击它,它就会执行一些操作。到目前为止,它运行得很好。现在我想给演员增加一些光。在做了一些研究之后,我偶然发现了Box2DLights。当我尝试将它添加到我的项目中时,onClick Actor运行良好,但似乎不起作用。我非常确定这是由于rayhandler/Box2DLights,因为这是我唯一做的更改。下面是我为包含Box2DLights所做的最小更改。

代码语言:javascript
复制
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

略低于实际参与者的工作

,这意味着坐标不知何故被筛选了(我知道很奇怪)。你能帮帮忙吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-01-29 01:12:11

感谢@Mikhail Thanks的回复,here。如果其他人再次发现这一点,这里有一个有效的解决方案。

代码语言:javascript
复制
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

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/48488569

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档